jQuery Event Menthods

Here are some common DOM events

1 Mouser Events

click dbclick mouseenter mouseleave

2 Keyborars Events

keypress keydown keyup

3 Form Events

submit change focus blus

4 Docment/Wiindow Events

laod resize scroll unload

click()
the function is executed when the user clicks on the html element.
eg:

 $("p").click(function(){
    $(this).hide();
})

dblclick()

the dblclick() method attaches an event handlerfunction to an html element. the function is executed when the user double-clicks on the html element

eg:

 $("p").dblclick(function(){
    $(this).hide();
})

mouseenter()
the function is executed when the mouse pointer the html element
eg:

 $("p").mouseenter(function(){
    alert("you entered p");
})

mouseleave()

the function is executed when the mouse pointer leaves the html element

eg:

    $("#p").mouseleave(function(){
    alert("bye! you now leave p");
    })

mousedown()
the function is executed , when the left,middle or right button is pressed down, while the mouse is over the html element
eg:

 $("p").mousedown(function(){
    alert("mouse down over p");
})

mouseup()

the function is excuted, when the left.midddle or right mouse button is released while the nouse is over the html element
eg:

$("p").mouseup(function(){
alert("mouse up over p");
})

hover()
the hover() method takes two functions and is a combination of the mouseenter() and mouseleave() methods
the first function is executed when the mouse enters enters the html element, and the second function is executed when the mouse leaves the html element

eg:

$("p").hover(function(){
alert("you entered p");
},funtion(){
alert("bye! you now leave p");
})

focus()
the focus() methods attaches an event handler function to an html form the function is executed when the form field gets focus

eg:

$("input").focus(function(){
$(this).css('background-color','#cccccc');
});

blur()
the blur() method attaches an eveent handler function to an html
the function is executed when the form field loses focus

$("input").blur(function(){
$(this).css('background-color','#ffffff');
})

on()
the function attaches one or more event handlers for selected selected
elements
eg:

$("p").on("click",function(){
$(this).hide();
})
    原文作者:hlcc
    原文地址: https://segmentfault.com/a/1190000008653656
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞