- Scenario : An element on the page bind multiple click event handlers, depending on the user's specific interaction, to determine which handler to use.
- Questions :
- Unbind will unbind all click events, causing accidental injury. If the previous bind has a method name that defines the handler, you can unbind the specified bind by passing the method name to Unbind's second argument, but in many cases the handler function of BIND is an anonymous function, at which point the second parameter of unbind cannot be processed.
- When the Click event occurs, you cannot specify that a specific event handler is called, only the function that should not be called is unbind out.
- resolution : Using namespaces, Namespace usage
<!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head> <title></title> <Scripttype= "Text/javascript"src= "Script/jquery-1.7.1.min.js"></Script> <Scripttype= "Text/javascript"> functionMyFunction1 () {alert (1); return false; } functionMyfunction2 () {alert (2); return false; } functionMyfunction3 () {alert (3); return false; } $(function () { $('#test'). Bind ('click.a', MyFunction1); $('#test'). Bind ('click.b', Myfunction2); $('#test'). Bind ('click.c', Myfunction3); $('#test'). Unbind ('click.a'); //$ (' #test '). Trigger (' click.b '); $('#test'). Trigger (); //$ (' #test '). Click (); }) </Script></Head><Body> <inputID= "Test"type= "button"name= "button"value= "button"width= "The "></Body></HTML>
Add '. ' After the event name (click) To specify the new naming, in this case, the new named A, B, and C, respectively, so that the specified function can be unbound at unbind, and the specified function can be called at trigger time. Many JS extensions use namespaces to differentiate themselves from events and avoid conflicts with the original events on the page.
- Reference Link: http://blog.csdn.net/clangke/article/details/7612224
Namespace usage for the Bind event in jquery (GO)