我正在这样做:
$("#bcdialog").dialog({
resizable: true,
height: 400,
width: 600,
modal: true,
autoOpen: false,
buttons: {
'cancel': function() { $(this).dialog('close'); }
'save': function() { $("#bcdialog form").submit(); }
}
});
我想知道是否可以使用它来代替#bcdialog form
最佳答案
也许给它上下文 this
会起作用,您仍然需要指定表单部分,但是给它上下文使它特定于您指定的选择器,而您没有对元素 ID 进行硬编码。
$("#bcdialog").dialog({
resizable: true,
height: 400,
width: 600,
modal: true,
autoOpen: false,
buttons: {
'cancel': function() { $(this).dialog('close'); }
'save': function() { $("form",this).submit(); }
}
});
:-)
关于jquery $(this) 而不是 $('#id 形式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3101166/