在jquery裡踩過的坑

來源:互聯網
上載者:User

標籤:版本   倒計時   span   fun   監聽   測試   www.   hang   https   

自己犯過的錯

一、parent()和parents()

parent(selector)指的是直系父元素parents(selctor)指的是沿DOM向上尋找所有父元素

 二、ie8中相容jquery的input事件(jquery1.11.3版本)

需求是即時監聽輸入框值變化,用的input[event],做相容性測試時發現在ie8下沒有作用,好像是ie9以下沒有input事件,解決方案:同時使用 input 和 兩種事件。

$("input").on("input propertychange",function(){   ... })

 三、寫十秒倒計時

原來用的是setInterval,然後清除掉,覺得並不適合。這次用setTimenout寫的,會在效率和寫法上更合適。

//設定倒數秒數  var t = 10;  //倒計時function time(){      t -= 1;      document.getElementById(‘times‘).innerHTML= t;      if(t==0){          location.href=‘https://www.cnblogs.com/‘;      }      setTimeout("time()",1000);  }time();

 四、相容html5

寫完之後測試不相容ie8,特別是@media,心塞啊

 <!--[if lt IE 9]>    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script><![endif]-->

解決方案,來自bootstrap。加的時候發現這段代碼需要載入樣式之後。

五、使用jquery的e.stopPropagation()無效

div.div1.事件1    div.div2.無事件        div.div3.事件3

層級和事件關係如上。需求是點擊div2的時候沒有任何事件,點擊div1和div3分別有事件。

直接寫

$(".div3").on("click",function(){e.stopPropagation()});

e.stopPropagation()並沒有生效。最後實踐得出:

$(".div1").on("click",function(){...});$(".div1").on("click",".div3",function(){e.stopPropagation()});

。。。還有問題TT

六、監控視窗的滾動(jquery1.11.3版本)

正常使用$(document).on("scroll",function(){})即可,但是測試發現在ie8下無效,改成$(window).on("scroll",function(){}),就好了,不是很理解。

 

在jquery裡踩過的坑

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.