您好,我有一个复选框,当我单击它并选中该框时,一个函数运行,它按照我想要的方式工作..现在我想运行一个不同的函数,如果它被选中但它只是运行每次都具有相同的功能。
<input type="checkbox" class="no-custom" onclick="CheckBox()">
function CheckBox() {
$("#emailMain").css({"display": "none"});
$("#emailSame").css({"display": "inline"});
var Mainemail = Customer().email['#text']();
Contact().email = Mainemail;
EmailHolder(Mainemail);
}
有什么解决此问题的最佳方法吗?
最佳答案
首先,如果您在页面中包含 jQuery,您应该使用它来附加您的事件,因为它可以更好地分离关注点。然后,您可以使用元素的 checked
属性来确定调用哪个函数:
<input type="checkbox" class="no-custom" />
$('.no-custom').change(function() {
if (this.checked) {
// do something...
}
else {
// do something else...
}
});
关于javascript - 复选框如果选中则触发一个功能,如果未选中则触发不同的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28064005/