我正在使用 MS Dynamics CRM 2013,我面临的问题是当我想将事件处理程序添加到导航 Pane 中的“文档”按钮时,
jQuery 函数 .on() 不适用于“点击”事件。它适用于“mouseover”或“mouseup”事件,但不适用于“click”。 这是我正在使用的代码:
$("#crmMasthead").on( "click", "#Node_navDocument", function(){ alert("Success!"); } );
Where:
#crmMasthead - static selector;
#Node_navDocument - id of the button "Documents", that I want to reload.
请帮我解决这个问题。提前致谢!
编辑
这是我正在处理的 html:
在用户打开 CRM 2013 中的导航 Pane 之前:
<body>
...
<div id="crmMasthead" tabindex="-1">
<div class="navStatusArea" id="navStatusArea"></div>
<div class='navBar' id='navBar'>...</div>
<div class="navBarOverlay" id="navBarOverlay" style="display: none;"> </div>
</div>
...
</body>
用户刚刚在 CRM 2013 中打开了导航 Pane :
<body scroll="no">
...
<div id="crmMasthead" tabindex="-1">
<div class="navStatusArea" id="navStatusArea"></div>
<div class='navBar' id='navBar'></div>
Changed:<div class="navBarOverlay" id="navBarOverlay" style="display: block;"></div>
New: <div class="navActionGroupContainer" style="">
...
<a class="navActionButtonContainer navActionButton navActionButtonDefault normal " id="Node_navDocument" role="button" title="Documents" href="javascript:;" unselectable="on" style="background-color: #555555">...</a>
...
</div>
</div>
...
</body>
最佳答案
不幸的是,由于 #Node_navDocument
元素的事件 click
,函数 .on() 在我的例子中不适用于 click
事件已经绑定(bind)到另一个使用 event.stopImmediatePropagation()
的系统函数,所有自定义逻辑在此之后不会执行。
但是,还有另一种方式......
为 click
事件实现自定义逻辑的主要目标是在该事件后显示具有不同 src
链接的系统 iframe
。所以,为了解决这个任务,我们接下来需要做的是:
- 为应该绑定(bind)元素 (2) 的
onclick
事件的一些静态元素 (1) 创建处理程序; - 在元素 (2) 的
onclick
事件上创建监听器,以观察 iframe 是否存在。
元素 (1) 有 id #TabNode_tab0Tab
,元素 (2) - #Node_navDocument
和 iframe -
#areaDocumentFrame
。
代码如下:
replaceDocumentsLink: function () {
console.log("Function was started!");
var listener = {};
window.top.$("#TabNode_tab0Tab").on("mouseover", function () {
if (window.top.$('#Node_navDocument').length)
window.top.$('#Node_navDocument')[0].onclick = function () {
listener = setInterval(function () {
if ($("#areaDocumentFrame").length) {
console.log("Frame was found!")
$("#areaDocumentFrame").attr("src", "http://www.microsoft.com/");
clearInterval(listener)
}
else
console.log("Frame was not found!")
}, 250);
}
});
关于javascript - jQuery 函数 .on() 不适用于 "click"事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22176124/