可能重复:
How to checkbox id to the modal box?
我有一个表格,每行都有一个复选框和一个按钮。只要按下按钮,就会出现一个模式框,同时复选框也会被选中。
如果想要删除特定的记录,模态框将询问用户。如果是,将提交表格。如果没有,则将不选中复选框。
我面临的问题是让复选框不被选中。有谁能帮忙处理示例代码吗?如何将复选框id传递给模式框,以便可以不选中该特定复选框?
谢谢。
var buttons3 = $("#yns button").click(function(e) {
// get user input
var yes = buttons3.index(this) === 0;
if (yes){
$('form#form1').submit();
return true;
}
else{
//How to get the particular Checkbox id so that it can be unchecked?
$(this).dialog("close");
return false;
}
});
发布于 2011-07-23 21:53:48
单击按钮时,获取复选框的id。
var id = $(this).parents('td').siblings()find('.checkbox').attr('id')
取消选中复选框
$('#'+id).attr("checked", false)
却不知道很多细节。这可能不是确切的答案.
发布于 2011-07-23 21:53:56
您可以将其分配给全局变量,并从模型对话框cancel事件进行访问。在复选框的onchange事件中,将复选框id分配给全局变量。在模型对话框的cancel事件中,您可以再次访问它。
var chk;
$("INPUT[type='checkbox']").click(function(event) {
chk= event.target.id;
});
发布于 2011-07-23 21:54:34
您可以通过使用带有按钮的公共根来查找复选框,然后将该对象存储到变量中,以便响应到取消操作的代码可以访问范围。我认为您可以很容易地使用来自Click处理程序的闭包,但是下面是使用window
对象作为占位符的代码。
jQuery > 1.6+
$('#table .button').click(function(){
//alter this selector to find the checkbox associated with the button.
window.my_checkbox = $("input[type='checkbox']",$(this).parent()).attr('checked','checked');
//load modal box...
if(cancel)
window.my_checkbox.removeAttr('checked');
});
jQuery < 1.5
$('#table .button').click(function(){
//alter this selector to find the checkbox associated with the button.
window.my_checkbox = $("input[type='checkbox']",$(this).parent()).prop('checked',true);
//load modal box...
if(cancel)
window.my_checkbox.prop('checked',false);
});
https://stackoverflow.com/questions/6805127
复制