單擊按鈕 痹兜,按鈕消失
$(document).ready(function(){
$("button").click(function(){
$(this).hide();
});
});
雙擊按鈕再登,按鈕消失
$("button").dblclick(function(){
$(this).hide();
})方篮;
鼠標(biāo)放上去有缆,按鈕消失
$("button").mouseenter(function(){
$(this).hide();
})骑丸;
鼠標(biāo)離開,按鈕消失
$("button").mouseleaver(function(){
$(this).hide();
})妒貌;
2.綁定事件和解除綁定事
$(document).ready(function(){
//$("#clickMeBtn").bind("click",clickHandler1);
//$("#clickMeBtn").bind("click",clickHandler2);
// $("#clickMeBtn").unbind("click",clickeHandler1);
$("#clickMeBtn").on("click",clickHandler1);
$("#clickMeBtn").on("click",clickHandler2);
$("#clickMeBtn").off("click",clickeHandler1);
});
function clickHandler(e){
console.log("clickHandler1")
}
function clickHandler(e){
console.log("clickHandler2")
}
3.事件的目標(biāo)和事件冒泡
阻止事件冒泡的API:
event.stopPropagation() //阻止父級的冒泡事件
event.stopImmediatePropagation()// 阻止所有的冒泡事件
5.自定義事件
var ClickMeBtn;
$(doucument).ready(function){
ClickMeBtn = $("#ClickMeBtn");
ClickMeBtn.click(function(){
var e =jQuery.Event("MyEvent");
ClickMeBtn.trigger(e);
});
ClickMeBtn.bind("MyEvent",function(event)){
console.log(event);
})
});