JQuery繫結事件與移除事件、動畫
阿新 • • 發佈:2019-01-02
繫結事件:bind()、on()、live()、delegate()、keyup();
觸發事件:trigger(‘keyup’)、keyup();
解綁事件:unbind()、off()、die()、undelegate();
符合事件:hover() 、toggle();
事件繫結:bind();
一、繫結事件
JQuery繫結事件,除 bing()
方法之外,還有 on()
、live()
、one()
等
事件的繫結方法。
繫結事件分類:
(a) 繫結單個事件
$("#btn").bind("click",function(){
//程式碼塊
console.log(123);
});
(b) 同時繫結多個事件
$("#btn").bind({
mouseover:function(){
$(this).css("background","red");
console.log("程式碼塊1");
},
mouseout:function(){
console.log("程式碼塊2");
},
click:function(){
console.log("點選事件");
}
});
二、移除事件
(a)使用 unbind() 方法 移除事件
$("button").click(function(){
$("p").unbind();
});
三、JQuery動畫
在Jquery 中,提供了一系列顯示動畫效果的方法,其中,
show()
——— 方法控制元素的顯示;hide()
———-方法控制元素的顯示;toggle()
——-方法切換元素的可見狀態;fadeIn()
——-方法淡入;fadeOut()
——方法淡出;slideUp()
——方法實現元素的收縮slideDown()
—方法實現元素的展開