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

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