js問題記錄

來源:互聯網
上載者:User

標籤:style   blog   io   color   sp   檔案   div   on   問題   

1:如果給type=file檔案添加change事件,如果點擊同一張圖片,則只會觸發一次onchange事件,因為change事件是根據value值定的,value不變無法觸發此事件。

live: function( types, data, fn ) {   jQuery( this.context ).on( types, this.selector, data, fn );   return this;}// jq 1.9以後live取消,從源碼可以看出可以用on代替
$(document).ready(function(){        // 點擊同一張檔案只能觸發一次    $("#file").change(function(){ alert("change"); });    $("#file").live("change", function () { alert("1"); });// live在jq 1.9以後就不用了,所以不能用live事件 live為一種特殊的delegate,代理宿主為body,效率不好    $("#file").on("change", function () { alert("1"); }); // 無效     $(‘body‘).delegate("#file","change",function(){alert("1");}); // 無效    // 可以在每次點擊的時候都觸發change事件,但是有個問題,每次file都會被清空一次,相當於沒有點擊    $("body").delegate("#file","change",function(){        $("#file").replaceWith("<input type=‘file‘ id=‘file‘ />");    });});

 

js問題記錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.