我正在尝试这段代码:
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
</body>
</html>
我希望当我点击p
时,网址的路径将更改为bar.html
。我正在从桌面上尝试此文件,因此URL看起来像file:///C:/Documents%20and%20Settings/Cupidvogel/Desktop/hist.html
。但是,当我点击p
时没有任何反应。我在这里做错了什么?