Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中调用方法时未更改全局变量_Javascript_Html_Global Variables - Fatal编程技术网

在javascript中调用方法时未更改全局变量

在javascript中调用方法时未更改全局变量,javascript,html,global-variables,Javascript,Html,Global Variables,我想获取index.html中表单操作中存在的文本字段的数据。我正在考虑使用javascript,如果还有其他方法可以获取html格式的表单数据,请提及 我的index.html是 <head><script type="text/javascript" src="js/storevalue.js"></script></head> <body> <form action="h.html" method="post">

我想获取index.html中表单操作中存在的文本字段的数据。我正在考虑使用javascript,如果还有其他方法可以获取html格式的表单数据,请提及

我的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>
我的h.html代码是

 <script type="text/javascript" src="js/storevalue.js"></script>
 <script type="text/javascript" charset="utf-8">
 function successCB() {valt();}
 </script>

函数successCB(){valt();}

页面刷新或重定向后,所有javascript数据都将从内存中删除。您可以使用cookies在不同页面上访问数据

当用户单击“提交”按钮时,您将用户发送到另一个页面,因此当您更改页面时,所有内容都将被丢弃

您需要/想要更改页面吗

如果没有,您可以将submit按钮替换为

您可以使用一些AJAX库提交搜索结果,并在返回结果时将其注入当前页面(因为您似乎是新手,我建议您使用element.innerHTML=htmlCode)

如果您更改页面,您可能希望使用一些服务器端脚本(如PHP)来进行搜索。 您必须处理url h.html?bran=XXX并使用它生成新的html页面。

storevalue.js只是一个“库”,它实际上不会存储值本身。index.html中有一个“b”变量,h.html中有另一个


通常在使用post提交表单时,服务器端读取并处理表单字段。你可以调用h.php或类似的东西。

好的,我在这里找到了链接,持久javascript变量可以通过包含此脚本而不使用cookie来创建

当我使用cookie时,是否有必要设置并从同一页面中的js获取cookie,因为当新页面h.html打开其不识别cookie i setNo时,没有必要,cookie对同一域上的所有页面都可见。我只需要使用html,这是我使用JavaScript的方式。使用cookie的另一种方法是使用GET方法而不是POST,然后在h.html中解析querystring。这将是非常奇怪的,但因为您只需要使用html。。
 <script type="text/javascript" src="js/storevalue.js"></script>
 <script type="text/javascript" charset="utf-8">
 function successCB() {valt();}
 </script>