• <bdo id='xvZgo'></bdo><ul id='xvZgo'></ul>
    1. <legend id='xvZgo'><style id='xvZgo'><dir id='xvZgo'><q id='xvZgo'></q></dir></style></legend>
      <tfoot id='xvZgo'></tfoot>

      1. <small id='xvZgo'></small><noframes id='xvZgo'>

      2. <i id='xvZgo'><tr id='xvZgo'><dt id='xvZgo'><q id='xvZgo'><span id='xvZgo'><b id='xvZgo'><form id='xvZgo'><ins id='xvZgo'></ins><ul id='xvZgo'></ul><sub id='xvZgo'></sub></form><legend id='xvZgo'></legend><bdo id='xvZgo'><pre id='xvZgo'><center id='xvZgo'></center></pre></bdo></b><th id='xvZgo'></th></span></q></dt></tr></i><div id='xvZgo'><tfoot id='xvZgo'></tfoot><dl id='xvZgo'><fieldset id='xvZgo'></fieldset></dl></div>

        事件是回调链中随处可访问的全局变量吗?

        时间:2023-09-05
            <bdo id='LLAwt'></bdo><ul id='LLAwt'></ul>
            <tfoot id='LLAwt'></tfoot>

            <small id='LLAwt'></small><noframes id='LLAwt'>

                <tbody id='LLAwt'></tbody>
              <legend id='LLAwt'><style id='LLAwt'><dir id='LLAwt'><q id='LLAwt'></q></dir></style></legend>

                  <i id='LLAwt'><tr id='LLAwt'><dt id='LLAwt'><q id='LLAwt'><span id='LLAwt'><b id='LLAwt'><form id='LLAwt'><ins id='LLAwt'></ins><ul id='LLAwt'></ul><sub id='LLAwt'></sub></form><legend id='LLAwt'></legend><bdo id='LLAwt'><pre id='LLAwt'><center id='LLAwt'></center></pre></bdo></b><th id='LLAwt'></th></span></q></dt></tr></i><div id='LLAwt'><tfoot id='LLAwt'></tfoot><dl id='LLAwt'><fieldset id='LLAwt'></fieldset></dl></div>
                  本文介绍了事件是回调链中随处可访问的全局变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我只是在玩弄 DOM 和 Javascript 的事件侦听器,并确实注意到了这一点:

                  I was just playing around with event listeners with DOM and Javascript and did notice this:

                  function chained(msg) {
                      console.log(msg, event);
                  }
                  
                  function onClick() {
                      chained('the body was clicked');
                  }
                  
                  document.body.addEventListener('click', onClick);
                  

                  现在有趣的是......这将输出:

                  Now the funny thing...this will output:

                  身体被点击,(MouseEvent)"

                  "the body was clicked, (MouseEvent)"

                  那我问,为什么?它如何传递事件对象而不在 chained 调用中发送它?

                  Then I ask, why? how does it passes the event object without sending it on the chained call?

                  function chained(msg) {
                      console.log(msg, namedEventObj); //throw error namedEventObj is not defined
                  }
                  
                  function onClick(namedEventObj) {
                      console.log(event); //outputs (MouseEvent);
                      console.log(nameEventObj); //outputs (MouseEvent);
                      chained('the body was clicked');
                  }
                  
                  document.body.addEventListener('click', onClick);
                  

                  即使我将要在 onClick 函数上传递的事件 obj 声明为 namedEventObj 它也只能用于 onClick 而不能用于 chained 函数...我知道了,这对我来说很有意义...但绝对不是 event 变量可用于 chained 函数.

                  Even If I declare the event obj to be passed on the onClick function as namedEventObj it will available only to onClick but not to chained function...I got this and this makes sense for me...but definitely not the event variable to be available to the chained function.

                  有人知道它为什么会这样吗?

                  Anyone know why does it behaves like this?

                  我唯一能想到的是事件实际上是 window.event 并且当某些事件调度和事件时它使自己可用......但这意味着任何元素都可以得到它事件触发时是否与事件同时调用?

                  The only thing I can think of is that event is in fact window.event and it makes itself available when some event dispatches and Event...but that would mean that any element could get that event information if called at the same time as the event when it triggers?

                  我使用的是 Chrome 11.0.x

                  I am using Chrome 11.0.x

                  推荐答案

                  可以通过window.event访问当前事件.仅仅使用 event 就是隐式访问 window.event.

                  One can access the current event through window.event. Just using event is implicitly accessing window.event.

                  这篇关于事件是回调链中随处可访问的全局变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:jQuery .on() 方法看不到新元素 下一篇:使用 submit() 从链接提交的表单无法被 onsubmit 处理

                  相关文章

                  最新文章

                    <bdo id='9IACa'></bdo><ul id='9IACa'></ul>
                  <tfoot id='9IACa'></tfoot>
                • <small id='9IACa'></small><noframes id='9IACa'>

                      <i id='9IACa'><tr id='9IACa'><dt id='9IACa'><q id='9IACa'><span id='9IACa'><b id='9IACa'><form id='9IACa'><ins id='9IACa'></ins><ul id='9IACa'></ul><sub id='9IACa'></sub></form><legend id='9IACa'></legend><bdo id='9IACa'><pre id='9IACa'><center id='9IACa'></center></pre></bdo></b><th id='9IACa'></th></span></q></dt></tr></i><div id='9IACa'><tfoot id='9IACa'></tfoot><dl id='9IACa'><fieldset id='9IACa'></fieldset></dl></div>

                      <legend id='9IACa'><style id='9IACa'><dir id='9IACa'><q id='9IACa'></q></dir></style></legend>