无法将事件处理程序附加到jQuery对话框页面

时间:2013-07-17 02:59:12

标签: javascript jquery events dialog

我有一个jquery对话框页面,请注明:

<div data-role="page" data-rel="dialog" data-close-btn="none">
<div data-role="header">
<h2>Failed to find driver</h2>
</div>
<div data-role="content">
<p>Failed to find a driver. Would you like to continue searching or cancel the search?        </p>
<a data-role="button" id="continueBtn" onclick="alert('continue')">Continue </a>
<a data-role="button" id="cancelBtn" onclick="alert('cancel')">Cancel </a>
</div>
</div>

这些警报在对话框中起作用。但是,我无法将其他功能的事件处理程序附加到这些按钮。如何将事件附加到这些按钮?

1 个答案:

答案 0 :(得分:1)

不要像你已经使用jquery那样做onclick="alert('cancel')"这样的事情..这样做吧

$("#cancelBtn").click(function(){
    alert('cancel');
});

http://api.jquery.com/click/

如果内容是动态加载的,则需要使用Jquery.on()

 $("#cancelBtn")on.("click",function(){
        alert('cancel');
 });
相关问题