我有以下代码,其中我在网址中附加带有哈希值的复选框值,但是当我从那里导航回来时,复选框没有被选中。请检查下面的代码
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car"> I have a car<br>
<script>
$checkboxes = $('input[type=checkbox');
$checkboxes.change(function(){
window.location.hash = 'check=' + $checkboxes.filter(':checked').map(function(){
return this.value;
}).get().join(",");
console.log(window.location.hash);
});
</script>
</body>
</html>
我应该在 url 中更改什么,以便在返回后取消选中复选框...
最佳答案
您要找的是
$(window).on("hashchange", function() {
// code here
}
但是,编写不清除每次哈希更改时的复选框的代码可能会很棘手。
关于javascript - 返回时,复选框未取消选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23926648/