0
点赞
收藏
分享

微信扫一扫

jQuery事件

1. trigger()

    // 触发相应事件,event为事件名,如click,没有on

$(selector).trigger(event,[param1,param2,...])



  // 使用事件对象触发

$(selector).trigger(eventObj)


2. select()  //文本被选中事件


3. animate() //动画函数

  1)支持使用相对值(相对当前值):

   

$("div").animate({
left:'250px',
height:'+=150px',
width:'+=150px'
});

  2)支持队列

$("button").click(function(){
var div=$("div");
div.animate({height:'300px',opacity:'0.4'},"slow");
div.animate({width:'300px',opacity:'0.8'},"slow");
div.animate({height:'100px',opacity:'0.4'},"slow");
div.animate({width:'100px',opacity:'0.8'},"slow");
});


    3)支持使用预定值

$("button").click(function(){
$("div").animate({
height:'toggle'
});
});


4. delegate()  给选中元素下的指定子元素绑定相应事件

  delegate() 方法为指定的元素(属于被选元素的子元素)添加一个或多个事件处理程序,并规定当这些事件发生时运行的函数。

  如果有多个事件,事件名用空格分隔

$(selector).delegate(childSelector,event,data,function)


5. on()  可以用来替代delegate(),用法也相近

6.  live()

$(selector).live(event,data,function)



live() 方法为被选元素附加一个或多个事件处理程序,并规定当这些事件发生时运行的函数。

通过 live() 方法附加的事件处理程序适用于匹配选择器的当前及未来的元素(比如由脚本创建的新元素)


7. bind()


$(selector).bind(event,data,function)



bind() 方法为被选元素添加一个或多个事件处理程序,并规定事件发生时运行的函数。

替代写法:

$(selector).bind({event:function, event:function, ...})



例如:

$("button").bind({
click:function(){$("p").slideToggle();},
mouseover:function(){$("body").css("background-color","red");},
mouseout:function(){$("body").css("background-color","#FFFFFF");}
});



举报

相关推荐

0 条评论