久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

      <tfoot id='dmiRY'></tfoot>

      1. <i id='dmiRY'><tr id='dmiRY'><dt id='dmiRY'><q id='dmiRY'><span id='dmiRY'><b id='dmiRY'><form id='dmiRY'><ins id='dmiRY'></ins><ul id='dmiRY'></ul><sub id='dmiRY'></sub></form><legend id='dmiRY'></legend><bdo id='dmiRY'><pre id='dmiRY'><center id='dmiRY'></center></pre></bdo></b><th id='dmiRY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='dmiRY'><tfoot id='dmiRY'></tfoot><dl id='dmiRY'><fieldset id='dmiRY'></fieldset></dl></div>

        • <bdo id='dmiRY'></bdo><ul id='dmiRY'></ul>
        <legend id='dmiRY'><style id='dmiRY'><dir id='dmiRY'><q id='dmiRY'></q></dir></style></legend>

        在 Jquery 中正確使用 .on 方法

        Proper use of .on method in Jquery(在 Jquery 中正確使用 .on 方法)
        • <bdo id='h92lX'></bdo><ul id='h92lX'></ul>
          <i id='h92lX'><tr id='h92lX'><dt id='h92lX'><q id='h92lX'><span id='h92lX'><b id='h92lX'><form id='h92lX'><ins id='h92lX'></ins><ul id='h92lX'></ul><sub id='h92lX'></sub></form><legend id='h92lX'></legend><bdo id='h92lX'><pre id='h92lX'><center id='h92lX'></center></pre></bdo></b><th id='h92lX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='h92lX'><tfoot id='h92lX'></tfoot><dl id='h92lX'><fieldset id='h92lX'></fieldset></dl></div>
          • <legend id='h92lX'><style id='h92lX'><dir id='h92lX'><q id='h92lX'></q></dir></style></legend>

                    <tbody id='h92lX'></tbody>

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

                  <tfoot id='h92lX'></tfoot>
                  本文介紹了在 Jquery 中正確使用 .on 方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我真的很喜歡 .live 方法,因為它簡單明了,與您的標準事件處理程序本質上沒有太大區(qū)別.

                  I really liked the .live method as it was straightforward and essentially not much different than your standard event handler.

                  唉,它已被棄用,我只剩下 .on 方法了.

                  Alas, it was deprecated and I'm left with the .on method.

                  基本上,我正在加載和動態(tài)加載需要觸發(fā)相同事件處理程序的內容.而不是添加事件處理程序兩次或多次..live 非常適合這個,但是 .on 已經取代了它,我似乎無法讓它工作.

                  Basically, I'm loading and dynamically loading content that I'll need the same event handler triggered on. Rather than add the event handler twice or however many times. .live was great for this, but .on has replaced it and I just can't seem to get it to work.

                  檢查此代碼:

                  jQuery('#who_me').live('click', function(){
                          alert('test123');
                          return false;
                      });
                  

                  應該與:

                  jQuery('#who_me').on('click', function(){
                          alert('test123');
                          return false;
                      });
                  

                  但是當我在 ajax 調用后用 .html 方法替換內容時,只有 live 方法有效.

                  but when I replace content with the .html method after an ajax call only the live method works.

                  誰能幫我解決這個問題?

                  Can anyone clear this up for me?

                  推薦答案

                  你沒有正確使用 .on().如果 #who_me 對象來來去去,這是一個更好的實現(xiàn).

                  You aren't using .on() correctly. This is a better implementation if the #who_me object comes and goes.

                  jQuery(document.body).on('click', '#who_me', function(){
                      alert('test123');
                      return false;
                  });
                  

                  您在 .on() 的 jQuery 對象中使用的選擇器必須是在您安裝事件處理程序時存在的對象,并且永遠不會被刪除或重新創(chuàng)建,并且要么是您的對象希望將事件安裝在該對象或其父對象上.作為第二個參數傳遞給 .on() 的選擇器是一個可選選擇器,它匹配您希望事件發(fā)生的對象.如果你想要 .live() 類型的行為,那么你必須在 jQuery 對象中傳遞一個靜態(tài)父對象,并在第二個參數中傳遞一個匹配你想要事件的實際對象的選擇器.

                  The selector you use in the jQuery object for .on() must be an object that is present at the time you install the event handler and never gets removed or recreated and is either the object you want the event installed on or a parent of that object. The selector passed as the 2nd argument to .on() is an optional selector that matches the object you want the event on. If you want .live() type behavior, then you must pass a static parent object in the jQuery object and a selector that matches the actual object you want the event on in the 2nd argument.

                  理想情況下,您可以在 jQuery 對象中放置一個相對接近動態(tài)對象的父對象.我展示了 document.body 只是因為我知道它會起作用并且不知道你的 HTML 的其余部分,但你寧愿把它放在更接近你的實際對象的地方.如果您在 document 對象或 document.body 上放置了太多動態(tài)事件處理程序,那么事件處理可能會真正變慢,特別是如果您有復雜的選擇器或處理程序頻繁點擊或鼠標移動等事件.

                  Ideally, you put a parent object in the jQuery object that is relatively close to the dynamic object. I've shown document.body just because I know that would work and don't know the rest of your HTML, but you'd rather put it closer to your actual object. If you put too many dynamic event handlers on the document object or on document.body, then event handling can really slow down, particularly if you have complicated selectors or handlers for frequent events like click or mousemove.

                  作為參考,100% 等效于您的 .live() 代碼是這樣的:

                  For reference, the 100% equivalent to your .live() code is this:

                  jQuery(document).on('click', '#who_me', function(){
                      alert('test123');
                      return false;
                  });
                  

                  .live() 只是將其所有事件處理程序安裝在文檔對象上,并使用事件冒泡來查看頁面中其他對象上發(fā)生的所有事件.jQuery 已棄用 .live() 因為最好不要在文檔對象上安裝所有實時事件處理程序(出于性能原因).因此,選擇一個更接近您的對象的靜態(tài)父對象.

                  .live() just installs all its event handlers on the document object, and uses event bubbling to see all the events that happen on other objects in the page. jQuery has deprecated .live() because it's better to NOT install all your live event handlers on the document object (for performance reasons). So, pick a static parent object that is closer to your object.

                  這篇關于在 Jquery 中正確使用 .on 方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                  anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項目中不起作用)
                  Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數據更新 Observable)
                  Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
                  In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何創(chuàng)建使用 Ionic 組件的自定義指令?)
                  Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態(tài)元素 - Angular 2 amp;離子2)

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

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

                        <bdo id='D0QhL'></bdo><ul id='D0QhL'></ul>

                        • <tfoot id='D0QhL'></tfoot>

                          1. <legend id='D0QhL'><style id='D0QhL'><dir id='D0QhL'><q id='D0QhL'></q></dir></style></legend>

                          2. 主站蜘蛛池模板: 国产精品一区在线 | 国产高清亚洲 | 91麻豆蜜桃一区二区三区 | 在线一区二区观看 | 91精品成人久久 | 在线观看国产视频 | 四虎影音| 成年男女免费视频网站 | 视频一区在线 | 久久成人精品视频 | 成人免费共享视频 | 久久久www| 韩国成人在线视频 | 久久免费小视频 | 免费精品一区 | 中文字幕 国产 | 国产精品乱码一区二区三区 | 亭亭五月激情 | 老外几下就让我高潮了 | 日本精品久久久久 | 羞羞视频网站在线观看 | 欧美一区二区三区在线视频 | 国产免费一区二区三区 | 午夜精品一区二区三区在线播放 | 午夜视频一区二区 | 久久久久国产一区二区三区四区 | 99亚洲综合 | 国产在线精品一区二区三区 | 亚洲免费大片 | 大乳boobs巨大吃奶挤奶 | 久久久久国产精品午夜一区 | 亚洲成人久久久 | 韩日在线视频 | 久综合| 请别相信他免费喜剧电影在线观看 | 国产精品免费一区二区三区 | 亚洲另类自拍 | 欧美黑人一级爽快片淫片高清 | 91久久久久久久久久久 | 成人精品一区亚洲午夜久久久 | 欧美午夜精品 |