开发者

Javascript: Remove checked status from disabled input (already checked)

开发者 https://www.devze.com 2022-12-30 21:59 出处:网络
Im trying to make this function to check an element and if its checked, or not, add or remove respective className. Also, if the element is disabled but i开发者_运维知识库s checked, it should un-check

Im trying to make this function to check an element and if its checked, or not, add or remove respective className. Also, if the element is disabled but i开发者_运维知识库s checked, it should un-check it and remove the className('yes')

function init() {
    $(document.body).select('input').each(function(element) {
        if (!element.checked) {
            element.up().removeClassName('yes');
        } else {
            element.up().addClassName('yes');
        }
        if (element.checked && element.disabled) {
            element.checked = false;
            element.up().removeClassName('yes')
        }
    });

}

Right now, the last part, is not working, no effect


Did you try element.checked = !element.checked in the last part instead of element.checked = false?

0

精彩评论

暂无评论...
验证码 换一张
取 消