<legend id='4E6bL'><style id='4E6bL'><dir id='4E6bL'><q id='4E6bL'></q></dir></style></legend>
  • <small id='4E6bL'></small><noframes id='4E6bL'>

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

    1. <tfoot id='4E6bL'></tfoot>

        为什么“事件"在 Chrome 中全局可用,但在 F

        时间:2023-09-05
          <tfoot id='cJPsd'></tfoot>
              <tbody id='cJPsd'></tbody>

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

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

                <legend id='cJPsd'><style id='cJPsd'><dir id='cJPsd'><q id='cJPsd'></q></dir></style></legend>
                1. 本文介绍了为什么“事件"在 Chrome 中全局可用,但在 FF 中不可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在解决另一个问题的答案时,出现了一个与 event 对象相关的奇怪错误,该对象可在匿名函数中使用而无需传入.在 Chrome 中,以下工作正常,但 FF 抛出一个错误.

                  While working on an answer for another question, a strange bug came up related to the event object being available in an anonymous function without being passed in. In Chrome the below works fine, but FF throws an error.

                  $(document).ready(function() {
                    $("#uspsSideboxTrackingClose").click(function() {
                      event.preventDefault();
                      console.log(event);
                    });
                  });
                  

                  铬:

                  火狐:

                  ReferenceError: 事件未定义

                  ReferenceError: event is not defined

                  <小时>

                  众所周知


                  It is already known that

                  $("#uspsSideboxTrackingClose").click(function(event) { .. }
                  

                  适用于两种浏览器.这里 是有问题的代码.这是 Chrome 或 FF 的错误,还是两种浏览器的预期行为?哪个浏览器合适?

                  works in both browsers. Here is the offending code. Is this a bug with Chrome or FF, or intended behavior by both browsers? Which browser is right?

                  推荐答案

                  在IE中,事件对象是一个全局对象,(它不传递给处理函数)但作为一个全局对象访问.您还可以将其作为窗口对象的属性来访问,例如 window.event

                  In IE, the event object was a global object, (which is not passed to the handler function) but accessed as a global object. You can also access it as a property of the window object like window.event

                  在 FF 和其他浏览器中,事件对象作为参数传递,因为在 FF 中没有名为 event 的全局属性,因此您会收到错误消息.

                  In in FF and other browsers the event object was passed as an argument, since in FF there is no global property called event, you are getting the error message.

                  在 chrome 中,他们添加了对这两个功能的支持,因此您将获取事件对象作为全局引用和参数.

                  In chrome they have added support for both these features, so you will get the event object as a global reference and as an argument.

                  但是由于您使用的是 jQuery,因此 jQuery 会规范化这两种行为,并将始终将事件对象作为参数传递给事件处理程序.

                  But since you are using jQuery, jQuery normalizes these 2 behaviors and will always pass the event object as an argument to the event handler.

                  $(document).ready(function () {
                      $("#uspsSideboxTrackingClose").click(function (event) {
                          event.preventDefault();
                          console.log(event);
                      });
                  });
                  

                  这篇关于为什么“事件"在 Chrome 中全局可用,但在 FF 中不可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:处理“onclick"纯 JavaScript 事件 下一篇:jQuery .on();与 JavaScript .addEventListener();

                  相关文章

                  最新文章

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

                    <legend id='1xvjV'><style id='1xvjV'><dir id='1xvjV'><q id='1xvjV'></q></dir></style></legend>

                    <small id='1xvjV'></small><noframes id='1xvjV'>