Javascript Can';t将事件处理程序附加到jQuery对话框页面
我有一个jquery对话框页面,如下所示:Javascript Can';t将事件处理程序附加到jQuery对话框页面,javascript,jquery,events,dialog,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
<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>
找不到驱动程序
找不到驱动程序。您要继续搜索还是取消搜索
继续
取消
这些警报在对话框中工作。但是,我无法将其他函数的事件处理程序附加到这些按钮。如何将事件附加到这些按钮?不要像使用jquery一样执行此操作。。像这样做
$("#cancelBtn").click(function(){
alert('cancel');
});
如果内容是动态加载的,则需要使用Jquery.on()
对话框的内容是否动态加载?你能分享一下事件处理程序是如何添加的吗警报只是一个测试;除了直接将它们放在html中,我没有其他选择。当我将页面切换到对话框时,$(document).ready函数不运行。编辑:在我完成输入之前,我不小心按了回车键
$("#cancelBtn")on.("click",function(){
alert('cancel');
});