1. Bind events Method 1:
Use this method to add events to elements when the page loads
$("#myElement").click(function(){
alert($(this). text());
})
Method 2:
Same as 1, you can also add events to elements after the page is loaded, such as creating new DOM elements
$("#myElement").bing('click' ,function(){
alert($(this).text());
})
2. Function declaration and named function expression Function declaration:
function myFun1() {
$("div").hide();
}
Call: myFun1();
Function expression:
var myFun2 = function(){
$("div").hide ();
}
Call: #("#myElement").click(myFun2);
Difference: The difference in calling time, Function declarations can be used anywhere, named function expressions can only be used after declaration
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn