你可以在创建jQuery别名时,在DevTools中获取事件监听器吗?

huangapple go评论47阅读模式
英文:

How can I get an event listener in DevTools when creating jQuery alias?

问题

我无法在Chrome DevTools和Firefox DevTools中获取事件侦听器,当创建一个不同的别名而不是使用jQuery.noConflict来使用jQuery时。

我想知道如何在使用jQuery noConflict时在Chrome DevTools或Firefox DevTools中获取事件侦听器。

<!-- 开始代码片段: js 隐藏: false 控制台: true Babel: false -->

<!-- 语言: lang-html -->

<script src="https://code.jquery.com/jquery-3.7.0.js"></script>

<!--
无法更改的外部js文件。
<script src="external.js"></script>
-->
<script>
// external.js的内容
  let $j = $.noConflict(true);
  (function($) {
    $(function() {
      init();
    });
    function init() {
      $('.click').on('click', function() {
        console.log('click');
        return false;
      });
    }
  })($j);
  $j = null;
</script>

<a href="#" class="click">click</a>

<!-- 结束代码片段 -->

你可以在创建jQuery别名时,在DevTools中获取事件监听器吗?

英文:

I can't get an event listener in Chrome DevTools and Firefox DevTools when creating a different alias instead of jQuery to use jQuery.noConflict

I would like to know how to get event listeners in Chrome DevTools or Firefox DevTools when using jQuery noConflict.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;script src=&quot;https://code.jquery.com/jquery-3.7.0.js&quot;&gt;&lt;/script&gt;

&lt;!--
external js file that I cannot change.
&lt;script src=&quot;external.js&quot;&gt;&lt;/script&gt;
--&gt;
&lt;script&gt;
//Contents of external.js
  let $j = $.noConflict(true);
  (function($) {
    $(function() {
      init();
    });
    function init() {
      $(&#39;.click&#39;).on(&#39;click&#39;, function() {
        console.log(&#39;click&#39;);
        return false;
      });
    }
  })($j);
  $j = null;
&lt;/script&gt;

&lt;a href=&quot;#&quot; class=&quot;click&quot;&gt;click&lt;/a&gt;

<!-- end snippet -->

你可以在创建jQuery别名时,在DevTools中获取事件监听器吗?

答案1

得分: 1

$j = $.noConflict(true);之后设置一个断点。然后,你可以手动分配一些其他变量来保存对这个版本的jQuery的引用:
myJQuery = $j;
然后,你可以使用myJQuery来替代$jQuery来访问被遮蔽的jQuery版本。

英文:

Set a breakpoint after $j = $.noConflict(true);. Then you can manually assign some other variable to hold a reference to this version of jQuery:

myJQuery = $j;

Then you can use myJQuery in place of $ or jQuery to access the shadowed version of jQuery.

huangapple
  • 本文由 发表于 2023年7月13日 09:41:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76675389.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定