0

我有一个 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>

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

4

1 回答 1

1

不要做这件事onclick="alert('cancel')",因为你已经在使用 jquery .. 这样做

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

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

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

 $("#cancelBtn")on.("click",function(){
        alert('cancel');
 });
于 2013-07-17T03:00:48.270 回答