美文网首页
checkbox codes

checkbox codes

作者: 佛系码农 | 来源:发表于2018-09-19 22:43 被阅读0次

function trClick() {
("#field_edit").delegate("tr", "click", function (e) { if (e.target.type === "checkbox") {//disable checkbox duplicate check event when click checkbox return; } if (event.ctrlKey) {//监听ctrl事件(this).css("background-color", "#fffde6");//设置背景色
let checkbox = (this).find("input");(checkbox).prop("checked", true);//通常使用prop,attr可能是由于jquery版本的问题有些情况不生效
} else {
(this).siblings().css("background-color", "");(this).siblings().find("input[type='checkbox']").removeAttr("checked");//checkbox取消选中

        $(this).css("background-color", "#fffde6");
        let checkbox = $(this).find("input[type='checkbox']");
        $(checkbox).prop("checked", true);
    }

    setChxTitleState();
});

}

//动态添加的元素绑定事件通常是采用:
//(document).on(event,"element",function(){}(document).on("click", "#field_edit input[type='checkbox']", function () {
if ((this).prop("checked")) {(this).parents("tr").css("background-color", "#fffde6");
} else {
$(this).parents("tr").css("background-color", "");
}

setChxTitleState();

})

//set column title
function setChxTitleState() {
let checkboxes = document.getElementsByName("ckb");
var checkNum = 0;
for (var i = 0; i < checkboxes.length; i++) {
var checkbox = checkboxes[i];
if (checkbox.checked) {
checkNum++;
}
}
if (checkNum === 0) {
("#check_title").prop("checked", false); } else if (checkNum === checkboxes.length) {("#check_title").prop("checked", true);
} else {
$("#check_title").prop("checked", false);
}
}

相关文章

网友评论

      本文标题:checkbox codes

      本文链接:https://www.haomeiwen.com/subject/ociinftx.html