美文网首页
jQuery的trigger()和e.data

jQuery的trigger()和e.data

作者: 李悦之 | 来源:发表于2017-05-26 00:50 被阅读90次
1、trigger()

trigger()是主动触发,意思就是说不需要做人为操作自己就会触发。

$('#div1').on('click',function(){
       $(this).animate({width:300},1000,'linear')
})
$('#div1').trigger('click')

注意trigger()接收的参数

2、e.data/type
$('#div1').on('click',{name:'limingru'},function(e){
       console.log(e.data.name)
       console.log(e.type)
       console.log(e.target)
 })

在事件绑定的函数里我们是没有办法传递参数的,因为它只有一个默认的e而且是在触发事件的时候才会传递。如果想要传递一些参数进去,就只能用e.data,e.data就是中间那个对象。

相关文章

网友评论

      本文标题:jQuery的trigger()和e.data

      本文链接:https://www.haomeiwen.com/subject/adltfxtx.html