有一个带有method="get“的html表单,没有动作&用type="submit”按钮
(function(){
jQuery(".time").text(Date.now());
})();
jQuery(".set-hash").on("click", function () {
location.hash = "hash";
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="get">
<div class="time"></div>
<input type="text" name="param">
<button type="submit">Submit</button>
<button type="button" class="set-hash">Set Hash</button>
</form>
案例1。
请看请求已发送。
案例2。
请看请求没有发送。什么都没变。
案例3。
确保只有在param更改时才发送请求。
所以问题是:,为什么只有在param更改时才发送请求?
P. S.
当更改方法从GET到POST时,一切都很好。但是我需要地址栏中的请求参数。
发布于 2014-12-12 14:18:48
它在这里工作,试试这个。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Doc title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(function(){
jQuery(".time").text(Date.now());
var url = window.location.href;
jQuery(".url").text(url);
jQuery(".set-hash").on("click", function () {
location.hash = "hash";
// alert("test");
});
});
</script>
</head>
<body>
<form method="get">
<div class="time"></div>
<input type="text" name="param">
<button type="submit">Submit</button>
<button type="button" class="set-hash">Set Hash</button><br />
Current URL:<div class="url"></div>
</form>
</body>
</html> 发布于 2014-12-14 07:45:01
还找不到原因。
问题似乎与浏览器处理某些特殊方式的锚有关。当我更改location.host浏览器时,尝试跳转到添加的锚点。这会影响提交按钮的处理。
必须使用变通方法-在localStorage中存储散列中的数据。
https://stackoverflow.com/questions/27439905
复制相似问题