1. The most direct mode, directly passing a function object into the method function, such as the following click (), the advantages of the disadvantage of a glance to know
$ ("#btnComfirmChooseCompany"). Click (function () { varCompanyName = ""; varCompanyID = ""; varhaschecked =false; varAllcheckbox = $ ("input[name= ' CompanyID ')"); for(vari = 0; i < allcheckbox.length; i++) { if(allcheckbox[i].checked = =true) {haschecked=true; CompanyID= $ (Allcheckbox[i]). attr ("value")); CompanyName= $("#"+CompanyID). Parent (). Next (). text (); } } //slightly});
2. Equivalent notation, define function independently to a variable
function Comfirmchoosecompany (e) { //e is optional parameter // ibid., slightly }// or var function (){}
The variable is then passed into the JS event function, and the effect feels the same, but as to what the difference remains to be understood
$ ("#btnComfirmChooseCompany"). Click ( comfirmchoosecompany// can run, think ... What is the effect of adding parentheses to company? A: Comfirmchoosecompany run directly ); $ ("#btnComfirmChooseCompany"). Click (function() { // equivalence notation, consider whether this business parenthesis can be omitted });
3.bind method
$ ("#allCheck"). Bind function () { $ ("[name = $chkItem]:checkbox"). attr ("Checked", $ (this). attr ("checked"));});
4.delegate method
$ ("Body"). Delegate function () { $ (this). addclass (' Tr_color '). Siblings ("tr"). Removeclass ("Tr_color");});
jquery Method Binding (event registration) Code Summary