在我的Javascript文件中,我有兩個不同複選框的監聽器,但是當我檢查/取消選中它們時,它們沒有被調用。下面是複選框的HTML:複選框未被調用的監聽器
<input type="checkbox" class="checkbox" name="ApproverCheckBox" id="@Approver[0]" checked/>@Approver[1]</li>
<input type="checkbox" class="checkbox" name="AccessorCheckBox" id="@entry[0]" checked/>@entry[1]</li>
這裏的JavaScript文件未執行部分:
$(document).ready(function() {
//listener for accessor checkbox
$('input[name=ApproverCheckBox]').change(function() {
if ($(this).is(':checked')) {
//AddAccessor(this.id);
alert("it is working");
}
else {
//RemoveAccessor(this.id);
alert("it is working");
}
});
//listener for approver checkbox
$('input[name=ApproverCheckBox]').change(function() {
if ($(this).is(':checked')) {
//AddApprover(this.id);
alert("it is working");
}
else {
//RemoveApprover(this.id);
alert("it is working");
}
});
});
我添加的警報他們同時測試...可能有人提供一些線索請點亮。 (添加HTML後地方)
//listener for accessor checkbox
$(document).on('change','input[name=ApproverCheckBox]', function() {
if ($(this).is(':checked')) {
//AddAccessor(this.id);
alert("it is working");
}
else {
//RemoveAccessor(this.id);
alert("it is working");
}
});
//listener for approver checkbox
$(document).on('change','input[name=ApproverCheckBox]', function() {
if ($(this).is(':checked')) {
//AddApprover(this.id);
alert("it is working");
}
else {
//RemoveApprover(this.id);
alert("it is working");
}
});
其工作http://jsfiddle.net/fJkpH/1/ –
該腳本在js小提琴中工作。是動態創建的HTML嗎? – JelleP
我確認它正在工作。你是否正確導入了jQuery庫? –