jQuery 特殊事件綁定

html 一些頁面元素按照通常的事件綁定方法會無效,這時要使用特殊的事件綁定 —— live 方法實現。

官方文檔說明(如下1.4版本)

.live( events, data, handler(eventObject) )

eventsA string containing a JavaScript event type, such as "click" or "keydown." As of jQuery 1.4 the string can contain multiple, space-separated event types or custom event names.

dataA map of data that will be passed to the event handler.

handler(eventObject)A function to execute at the time the event is triggered.


1. html img 標籤的 點擊事件綁定

jQuery("#img_query").live("click", "img", function () {
         alert('click img');
});

2. input :file 瀏覽文件的標籤 onchanged

    $("#photo_file").live("change","input",function () {
        alert("file selected has changed");
    })

注:本文使用的 jquery  版本是 jquery. 1.4.1 .js

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章