停止事件传播不起作用 [英] Stop event propagation not working
问题描述
专家,
我正在使用 Obout 网格,并且它已经注册了 onmousedown 和 onclick 事件(此事件是内置事件或默认情况下).
现在,我不希望发生上述事件,因此我编写了以下代码来停止执行该事件,如果将警报放置在 stopEventPropagation(e)函数中,则此方法可以正常工作,否则不会工作.
这是我编写的代码:
Hi Expert,
I am using Obout grid and its already has onmousedown and onclick event registered (this event is inbuilt or by default).
Now I don''t want the above event so I have written the following code to stop executing the event and this is working fine if I place the alert inside the stopEventPropagation(e) function, else does not work.
Here is the code that I have written:
<script language="javascript" type="text/javascript">
function stopEventPropagation(e) {
if (!e) { e = window.event; }
if (!e) { return false; }
/*
if i am removing or comment
alert('bug')
then the code is not working as aspectated else it is working well.
*/
alert('bug');
e.cancelBubble = true;
e = null;
if (e.stopPropagation) { e.stopPropagation(); }
}
function assignEventsToCheckboxes(oboutGrid) {
// disable the record selection feature by clicking on the records
var sRecordsIds = oboutGrid.getRecordsIds();
var arrRecordsIds = sRecordsIds.split(",");
for (var i = 0; i < arrRecordsIds.length; i++) {
var oRecord = document.getElementById(arrRecordsIds[i]);
oRecord.onmousedown = function (e) { stopEventPropagation(e); };
oRecord.onclick = function (e) { stopEventPropagation(e); };
}
}
</script>
我在身体负荷时调用函数AssignEventsToCheckboxes.
I call the function assignEventsToCheckboxes on body load.
<body onload="assignEventsToCheckboxes(ogrdWorkOrder);">
注意:- 该事件是由第三方控件分配的,我想从控件中删除此事件.
您的回答将不胜感激!
提前谢谢.
Imdadhusen
Note:- The event was assigned by the third party control and i want to remove this event from control.
Your answer will be appreciated!:thumbsup:
Thanks in advance.
Imdadhusen
推荐答案
我最近也遇到过同样的问题.这只是时间问题,因此您需要延迟一些时间.在代码中的适当位置使用setTimeout()
.对我来说,它正在工作.我希望这也能解决您的问题.
顺便说一句,对不起您的答复.
Hi, I have faced the same kind of issue recently. It''s just timing issue so you need to give some delay. UsesetTimeout()
in appropriate place in your code. For me it''s working. I hope this will resolve your problem too.
BTW sorry for the late reply.
这篇关于停止事件传播不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!