防止复选框在单击时取消选中(不禁用或只读)

2024-01-06

I'm using a checkbox and I want people to be able to check/uncheck it. However, when they uncheck it, I'm using a jQueryUI modal popup to confirm that they really want to do that. Thus they can click OK or Cancel, and I want my checkbox to be unchecked only if they click OK.
That's why I would like to catch the uncheck event to prevent the checkbox from being visually unchecked, and uncheck it myself programmatically if the user happens to click on OK.

我怎么能这么做呢?

PS: I know I could re-check it after if the user clicks on Cancel but that would trigger the check event which I do not want.


$("#checkboxID").on("click", function (e) {
    var checkbox = $(this);
    if (checkbox.is(":checked")) {
        // do the confirmation thing here
        e.preventDefault();
        return false;
    }
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

防止复选框在单击时取消选中(不禁用或只读) 的相关文章

随机推荐