jquery带参数绑定事件 bind(type,[data],fn)

bind 方法为每个选择的元素事件绑定函数
语法格式:bind(type,[data],fn)
其中参数type为一个或多个类型字符串参数,type参数选择范围如下:
blur,focus,load,scroll,unload,click,
dbclick,mousedown,mouseup,mousemove,mouseover,
mouseout,mouseenter,mouseleave,change,select,submit,
keydowm,keypress,keyup,error
参数data是作为event.data属性值传递给事件对象额外的数据对象
参数fn是绑定到每个选择元素的事件中的处理函数
$(function(){
    $(“#button1”).bind(“click”,function(){
    $(this).attr(“disabled”,”disabled”);
    })//按钮不可用
})

如需绑定多个事件,可以将事件用空格隔开,下面我们添加一个click 一个mouseout时间

$(function(){
     $("body ,div ,#button1").bind("click mouseout",function(){
         $(this).attr("disabled","disabled");
     })
})

$(function(){
   $(“.txt”).bind({
       focus:function(){$(“#idTip”).show().html(“执行的是focus事件”);},
       change:function(){$(“#idTip”).show().html(“执行的是change事件”);}
   })
})

在参数bind()方法中,第二个参数data很少用到,用途是通过该参数把一些附加的信息传递给事件处理函数fn中
   $(function(){
      var message=”把该信息传递给Fn函数”;
       $(“.txt”).bind(“focus”,{msg:message},
       function(event){
           $(“#idTip”).show().html(even.data.msg);}
        );//设置文本

})

        

复制代码

带参数绑定函数用法

function handler(event) {
  alert(event.data.foo);
}
$("p").bind("click", {foo: "bar"}, handler)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值