我有一个表格,每一行都是一个表格。在某一行的单元格上有一个删除按钮。我需要一个jquery模式对话框确认删除时,一个复选框点击。我尝试了javascipt incuded,但只对第一行有效。
$(document).ready(function(){
$("#dialog").hide();
});
$('#Wcheckboxcd1').click(function(e) {
var form = $("form").attr("id");
$("#dialog").dialog({
buttons : {
"Διαγραφή" : function() {
document.getElementById(form).submit();
$(this).dialog("close");
},
"Ακύρωση" : function() {
document.getElementById(form).Wcheckboxcd.checked = 0;
$(this).dialog("close");
}
}
});
})发布于 2014-09-26 18:19:29
var form = $("form").attr("id")
..。目标为:
var form = $(this).closest('tr').find('form').attr('id');
这将从"delete“按钮的行中选择表单,而不是始终选择第一个form。有关更多信息,请参阅重用ID Wcheckboxcd1的closest().
name属性,因为您使用的是forms。还要注意,当您即将拥有包含表单元素的jQuery对象时,使用document.getElementById是非常多余的。考虑使用下面这样的代码;
$('[name="Wcheckboxcd1"]').click(function(e) {
$("#dialog").dialog({
buttons : {
"Διαγραφή" : function() {
$(this).closest('tr').find('form').submit();
$(this).dialog("close");
},
"Ακύρωση" : function() {
this.checked = false;
$(this).dialog("close");
}
}
});
})。。以上假设您已经更改了您的:
<input type="checkbox" id="Wcheckboxcd1" />至:
<input type="checkbox" name="Wcheckboxcd1" />https://stackoverflow.com/questions/26057241
复制相似问题