取消选中 Mozilla 刷新的复选框

Uncheck Checkboxes on Mozilla Refresh

本文关键字:复选框 刷新 Mozilla 取消      更新时间:2023-09-26

我注意到Mozilla的刷新并没有使页面陷入空白。我在表单上有复选框,在加载/刷新页面时需要取消选中。目前我正在使用这个:

<body onLoad="uncheck()">
function uncheck() {
    // Uncheck all checkboxes on page load    
    $("input:checkbox:checked").attr("checked", "");
    console.log("uncheck");
}

这适用于完全加载页面,但是如果我单击刷新(在 Mozilla 中),则会正确调用该函数,因为"取消选中"正在打印到控制台,但复选框仍处于选中状态。

有什么想法吗?

改用 prop

$(':checkbox:checked').prop('checked',false);

或删除属性:

$(':checkbox:checked').removeAttr('checked');

通过将窗口卸载设置为任何内容来禁用"页面缓存"

window.onunload=function(){return true;};