Javascript 使用GET方法和location.hash值提交表单
有一个方法为get的html表单,没有类型为submit的操作和按钮 作用{ jQuery.time.textDate.now; }; jQuery.set-hash.onclick,函数{ location.hash=hash; }; 提交 设置散列Javascript 使用GET方法和location.hash值提交表单,javascript,html,forms,Javascript,Html,Forms,有一个方法为get的html表单,没有类型为submit的操作和按钮 作用{ jQuery.time.textDate.now; }; jQuery.set-hash.onclick,函数{ location.hash=hash; }; 提交 设置散列 它在这里工作试试这个 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text
它在这里工作试试这个
<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>
还找不到原因 问题似乎与浏览器以某种特殊方式处理的锚有关。当我更改位置时。主机浏览器尝试跳转到添加的定位点。这会影响提交按钮的处理
必须使用变通方法-将散列中的数据存储在本地存储中。尝试将其他操作放到表单中。尝试了,没有帮助。看起来是位置的问题。谢谢,但有什么区别?我只看到了。添加了url操作。请检查脚本。我想,括号的顺序不对。您的函数在调用dateChecked后被终止,但不起作用:当设置哈希时-时间没有更改您是否在ready函数中保留了date和click func?它应该可以工作。是的,两个函数都在ready函数中。Chrome last+win7、Firefox last+win7不工作