我想要在index.html中的表单动作中获取文本字段的数据。我正在考虑与JavaScript做什么,如果有任何其他方式获得HTML格式的数据请提及它。全局变量在javascript中调用方法时不会发生变化
我的index.html是
<head><script type="text/javascript" src="js/storevalue.js"></script></head>
<body>
<form action="h.html" method="post">
<input type="text" name="bran" value="Enter Brand/Molecule" id="searchstring"/>
<input type="submit" value="Brand" class="right" id="startsearchbutton" onclick="st_v();>
</form>
</body>
我storevalue.js是
var b;
function st_v(){b=document.getElementById('searchstring').value; }
function valt(){
alert("in val="+window.b);//printing in val=undefined
}
我h.html代码
<script type="text/javascript" src="js/storevalue.js"></script>
<script type="text/javascript" charset="utf-8">
function successCB() {valt();}
</script>
当我使用Cookie是有必要设置和获取由存在于同一页面JS cookie的,因为如新页面h.html打开其无法识别的cookie,我设置了 – saum22 2012-02-16 11:56:23
不需要,cookie对同一域中的所有页面都可见。 – Ivan 2012-02-20 11:05:39