如何使用事件冒泡取消 [英] how to use event bubbling cancellation

查看:85
本文介绍了如何使用事件冒泡取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处都在寻找有关如何阻止事件冒泡发生的代码,并且我在Quirksmode网站上找到了一个代码:

I've looked everywhere for a code on how to stop event bubbling to occur, and I've found one from the Quirksmode website, which is this:

function doSomething(e){
    if(!e) var e = window.event;
    e.cancelBubble = true;
    if(e.stopPropagation) e.stopPropagation();
}

但是我不知道如何以及在哪里使用它. "e"参数用作什么(或应作为"e"传递)? 是否在事件处理程序代码中调用此函数? ...等等?

But I don't know how and where to use it. What is the 'e' parameter used as (or what should be passed as 'e')? Is this function to be called in an event handler code? ...etc?

我需要一些帮助,请有人可以给我一些提示吗?

I need some help, please can someone give me some hint?

基本上,我有4个元素具有一个名为"updateAvailableAttributes()"的"onchange"处理程序,如下所示:

Basically I have 4 elements that have an 'onchange' handler called 'updateAvailableAttributes()', like this:

<select id="deliveryMethod" name="deliveryMethod" onchange="updateAvailableAttributes();"></select>

<select id="formatMethod" name="formatMethod" onchange="updateAvailableAttributes();"></select>

<select id="yearsMethod" name="yearsMethod" onchange="updateAvailableAttributes();"></select>

<select id="updateMethod" name="updateMethod" onchange="updateAvailableAttributes();"></select>

这是updateAvailableAttributes()脚本:

Here is the updateAvailableAttributes() script:

function updateAvailableAttributes() {
var form = document.forms["orderDefinition"];
form.elements["formChangeRequest"].value = "true";
$.ajax({
  type: "POST",
  url: "ajax/possibleValues.html",
  data: $("form#orderDefinition").serialize(),
  success: function(response){
    $('#usercontent .sleeve .toprow').html(response);

    applyValidation();
    radioButtonHighlightSelection();

  },
  error: function(response, ioArgs) {
         if (response.status == 601) {
             sessionTimedOut();
         } 
      }
});

// Display a "please wait" message
$("#waitingMsgOverlay, #waitingMsgBox, #waitingMsg, #waitingMsgParag").ajaxStart(function(){
      var map = document.getElementById("OrderMap");
      map.disableApplication();
      $(this).show();
      radioButtonHighlightSelection();
  }).ajaxStop(function(){
      var map = document.getElementById("OrderMap");
      map.enableApplication();
      $(this).hide();
      $("#toolpanel").height($("#orderMap").height());
      radioButtonHighlightSelection();
});}

我的问题是,如何将'doSomething(e)'与'onchange'事件处理程序中已有的'updateAvailableAttributes()'合并?

My question is, how do I incorporate the 'doSomething(e)' with 'updateAvailableAttributes()' I have already on the 'onchange' event handler?

谢谢.

推荐答案

e是事件.例如,如果您在另一个div内有一个div,并且它们两个都有一个名为doS​​omething的js单击处理程序.因此在onclick属性中使用onclick ="doSomething(event);"如果您单击内部div外部,现在将无法处理

e is the event. For example if u have a div inside another div and both of them have a js click handler called doSomething. so in the onclick attribute use onclick="doSomething(event);" if you click on the inner div outer will not handle it now

这篇关于如何使用事件冒泡取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆