javascript 取消选中 Mozilla 刷新上的复选框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10954839/
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
Uncheck Checkboxes on Mozilla Refresh
提问by Kevin_TA
I've noticed that Mozilla's refresh doesn't bring the page to a blank slate. I have checkboxes on the form that I need to be unchecked when the page is loaded/refreshed. Currently I am using this:
我注意到 Mozilla 的刷新不会使页面变成空白。我在表单上有复选框,当页面加载/刷新时我需要取消选中它们。目前我正在使用这个:
<body onLoad="uncheck()">
function uncheck() {
// Uncheck all checkboxes on page load
$("input:checkbox:checked").attr("checked", "");
console.log("uncheck");
}
This works for loading the page completely, but if i click refresh (in Mozilla) the function is called properly because "uncheck" is being printed to the console, but the checkboxes are remaining checked.
这适用于完全加载页面,但如果我单击刷新(在 Mozilla 中),该函数将被正确调用,因为“取消选中”正在打印到控制台,但复选框仍处于选中状态。
Any thoughts?
有什么想法吗?
回答by Engineer
Use propinstead:
改用道具:
$(':checkbox:checked').prop('checked',false);
or removeAttr:
$(':checkbox:checked').removeAttr('checked');
回答by kennebec
Disable the 'page cache' by setting window onunload to anything at all-
通过将 window onunload 设置为任何内容来禁用“页面缓存”-
window.onunload=function(){return true;};