【问题标题】:Can't attach event handlers to jQuery dialog page无法将事件处理程序附加到 jQuery 对话框页面
【发布时间】:2013-07-17 02:59:12
【问题描述】:

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

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

【问题讨论】:

  • 对话框的内容是动态加载的吗?你能分享一下如何添加事件处理程序

标签: javascript jquery events dialog


【解决方案1】:

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

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

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

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

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

【讨论】:

  • 警报只是一个测试;我没有找到直接将它们放在 html 中的替代方法。当我将页面切换到对话框时,$(document).ready 函数不会运行。编辑:我在完成输入之前不小心按了 Enter
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-30
  • 1970-01-01
相关资源
最近更新 更多