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