简体   繁体   English

复选框返回后未取消选中

[英]Checkbox not getting uncheck after going back

I have a code where im using some checkboxes on click of them im appending the checkbox value in url with hash but when i go back or press back button url gets changes but checkbox remains checked.Please check the code as follows 我有一个代码,其中即时消息使用一些复选框,即时消息将它们添加到带有哈希值的URL中,但是当我返回或按下返回按钮时,URL得到更改,但复选框仍处于选中状态。请检查代码如下

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$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>

<input type="checkbox" name="check" value="one">one<br>
<input type="checkbox" name="check" value="two">two<br>
<input type="checkbox" name="check" value="one">three<br>
<input type="checkbox" name="check" value="two">four<br><input type="checkbox" name="check" value="one">five<br>
<input type="checkbox" name="check" value="two">six<br><input type="checkbox" name="check" value="one">seven<br>
<input type="checkbox" name="check" value="two">eight<br>
</body>
</html>

Right now when i click back after checking some checkboxes,url gets changed.but the checkbox still remains checked.How can i make checkbox unchek after going back once i checked some checkboxes... 现在,当我在选中某些复选框后单击返回时,URL更改了。但是该复选框仍然处于选中状态。一旦我选中了某些复选框,如何在使复选框退格后取消选中...

Here you can use hashchange function of javascript / jQuery. 在这里,您可以使用javascript / jQuery的hashchange函数。

window.onhashchange = function () {//add you logic here to check difference in url alert(window.location.hash);};

Or you can use jQuery's hashchange function. 或者,您可以使用jQuery的hashchange函数。

$(window).on('hashchange', function() {
     alert(window.location.hash);
});

you can use any one of the above function to get manipulation on hash URL. 您可以使用上述任何一种功能来对哈希网址进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM