UNe*_*rNo 0 javascript jquery jquery-ui jquery-dialog
我编写了以下代码,创建了一个带有动态添加内容的弹出窗口.现在我想删除这些添加的项目或编辑它们,但它似乎没有点击其中一个按钮的事件(btnLSM_Remove + btnLSM_Edit).任何线索为什么会这样?btnLSM_Add并btnLSM_Okay以同样的方式工作,他们工作......
function ListManagementDialog(obj, dialogTitle, dialogText, listDelimiter, btnNames) {
if (!$.isArray(btnNames)) {
return false;
}
if (dialogConfirmed) {
return false;
}
btns[btnNames[0]] = function () {
$(this).dialog('close');
dialogConfirmed = true;
if (obj) {
obj.click();
}
};
btns[btnNames[1]] = function () {
$(this).dialog('close');
};
$('body').append(String.Format('<div id="divLSM_Dialog" title="{0}"><p>{1}</p>' +
'<button id="btnLSM_Add" class="btnAdd" type="button" role="button" aria-disabled="false" title="Hinzufügen" />' +
'<input id="txbLSM_Emailadresse" class="text ui-widget-content ui-corner-all" type="text" name="txbLSM_Emailadresse" style="display:none;">' +
'<button id="btnLSM_Okay" class="btnOkay" type="button" role="button" aria-disabled="false" title="Übernehmen" style="display:none;" />' +
'<br /><br />' +
'<table id="tblLSM_Items" class="ui-widget ui-widget-content">' +
'<thead>' +
'<tr class="ui-widget-header ">' +
'<th>Emailadresse</th>' +
'<th />' +
'</tr>' +
'</thead>' +
'<tbody />' +
'</table>' +
'</div>', dialogTitle, dialogText));
$('#btnLSM_Add').click(function () {
$('#txbLSM_Emailadresse').val('');
$('#txbLSM_Emailadresse').show();
$('#btnLSM_Okay').show();
$('#txbLSM_Emailadresse').focus();
});
$('#btnLSM_Okay').click(function () {
$('#tblLSM_Items tbody').append('<tr>' +
'<td>' + $('#txbLSM_Emailadresse').val() + '</td>' +
'<td>' + '<button id="btnLSM_Remove" class="btnRemove" type="button" role="button" aria-disabled="false" title="Entfernen" />' + '<button id="btnLSM_Change" class="btnEdit" type="button" role="button" aria-disabled="false" title="Ändern" />' + '</td>' +
'</tr>');
$('#txbLSM_Emailadresse').hide();
$('#btnLSM_Okay').hide();
});
$('#btnLSM_Remove').click(function () {
alert("hohoho"); //no alert-popup
});
$('#btnLSM_Change').click(function () {
alert("hohoho"); //no alert-popup
});
$('#divLSM_Dialog').dialog({
modal: true,
resizable: false,
draggable: true,
width: 600,
height: 300,
close: function (event, ui) {
$('body').find('#divLSM_Dialog').remove();
},
buttons: btns
});
return dialogConfirmed;
}
Run Code Online (Sandbox Code Playgroud)
您致电时,您的btnLSM_Remove按钮不存在
$('#btnLSM_Remove').click(function () {
Run Code Online (Sandbox Code Playgroud)
所以$('#btnLSM_Remove')集合是空的,处理程序被添加到任何东西.
你可以使用on函数:
$('#divLSM_Dialog').on('click', '#btnLSM_Remove', function () {
Run Code Online (Sandbox Code Playgroud)
注册将应用于委托定义之后出现的按钮的处理程序.
编辑:
在jQuery 1.6.2中,您可以使用live:
$('#btnLSM_Remove').live('click', function () {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2586 次 |
| 最近记录: |