jQuery 特殊事件绑定

本文介绍jQuery中live方法的使用方式及应用场景,适用于1.4版本。通过实例演示了如何为html元素绑定click和change事件,解决常规事件绑定不生效的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值