我正在使用此功能更改模态按钮的ID
$('#editRevision a').click(function()
{
//clear the uploadify queue
$('#file_upload').uploadifive('clearQueue');
//change the id of the footer next button to pagesOrdered
$('#next').attr('id' , 'pagesOrdered');
});
只是为了检查'.on('click',function())是否正常工作我使用以下
//Pages ordered click
$('#pagesOrdered').on('click',function()
{
alert('Testing');
});
我的提醒未触发,但如果我将#pagesOrdered
更改回#next
则会触发。从DOM中释放#next我需要做什么。
谢谢!
答案 0 :(得分:2)
$('#pagesOrdered')
不存在。您可以在更改id
或将on()
委托给更高级别的DOM树并使用#pagesOrdered
作为选择器
第一种方法:
$('#editRevision a').click(function(){
//clear the uploadify queue
$('#file_upload').uploadifive('clearQueue');
//change the id of the footer next button to pagesOrdered
$('#next').attr('id' , 'pagesOrdered');
//Pages ordered click
$('#pagesOrdered').on('click',function(){
alert('Testing');
});
});
第二种方法:
$(document).on('click','#pagesOrdered',function(){
alert('Testing');
});
在更改#next
之前,您还应解除附加到id
的事件的绑定。更改id
不会删除它们。在不改变id
的情况下,比如切换类并在处理程序中运行类特定代码,可能是一种更简单的方法来处理你正在做的事情