$("#" + inputId).on("input", function () { var checkboxId = $("#" + inputId).attr("target"); if ($("#" + inputId).val().length == 0) { //關閉復選框 if ($("#" + checkboxId).next().hasClass("layui-form-checked")) { $("#" + checkboxId).next().click(); } } else { //開啟復選框 if (!$("#" + checkboxId).next().hasClass("layui-form-checked")) { $("#" + checkboxId).next().click(); } } })