javascript 如何取消选中后退按钮上的复选框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20650536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to uncheck checkbox on back button?
提问by Java Curious ?
Hi I have numbers of check boxes and below that I have a Button, which will filter data as per check box selection..
嗨,我有许多复选框,下面有一个按钮,它将根据复选框选择过滤数据。
When I will click on filter button it will transfer to other page and when I click on back button the checkbox reamains checked.
当我点击过滤器按钮时,它会转移到其他页面,当我点击后退按钮时,复选框保持选中状态。
but I want that when I click on back button then checkbox should be uncheck.
但我希望当我点击后退按钮时,复选框应该取消选中。
Any help.
任何帮助。
回答by Mr. Alien
You can reset the checkboxes on page load using jQuery
您可以使用 jQuery 在页面加载时重置复选框
$('input:checkbox').prop('checked', false);
Demo(Checkbox will be never checked as onload
am getting rid of checked
property)
演示(复选框将永远不会被选中,因为onload
我正在摆脱checked
财产)
ondomready
(Place the below code anywhere in your document)
ondomready
(将以下代码放在文档中的任何位置)
$(document).ready(function(){
$('input:checkbox').prop('checked', false);
});
回答by ohkts11
For those who have similar issues, add autocomplete="off"
to checkbox might help.
对于那些有类似问题的人,添加autocomplete="off"
到复选框可能会有所帮助。
回答by Sridhar R
Try this when back button is clicked Use Jquery to clear the checkboxes
单击后退按钮时尝试使用 Jquery 清除复选框
$("input[type='checkbox']").each( function() {
$(this).removeAttr('checked');
});
回答by Yagnesh Agola
You may use below code :
您可以使用以下代码:
window.onbeforeunload = function() {
//unchecked your check box here.
$("input[type='checkbox']").prop('checked', false)
};