unbind(type [,data]) //data is Function to be removed
$('#btn').unbind("click"); //Remove click
$('#btn').unbind(); //Remove all
For situations that only need to be triggered once and then unbind immediately, use one()
$('#btn').one("click",function(){.....});
Trigger operation
trigger() method triggers the specified event type of the selected element.
$('#btn').trigger("click ");
You can also directly execute the event
$('# btn').click();
Trigger custom events
The bind() method adds one or more event handlers to the selected element and specifies the function to run when the event occurs.
$('#btn').bind("myclick ",function(){....});
Simulate triggering the above binding function
$( '#btn').trigger("myclick");
Pass data trigger(event,[param1,param2,...])
$('#btn').bind("myclick",function(event,message1,message2){.............});
$(' #btn').trigger("myclick",["pass to message1","pass to message2"]);
Trigger execution of the default action
$("input" ).trigger("focus");
//It will not only trigger the focus event bound to the input element, but also trigger the default operation - get focus
Only triggers binding events and does not perform browser default operations
$("input").triggerHandler("focus");
//Only trigger the binding event and do not perform the browser default operation
Other uses
Bind multiple event types
$(" div").bind("mouseover mouseout",function(){.....});
Add event namespace
$("div" ).bind("click.plugin",function(){......});
Add a namespace after the bound world type, so that you only need to specify the namespace when deleting an event.
$("div").unbind(".plugin "); //Delete events in the space
$("div").trigger("click!"); //Trigger the click method that is not included in the namespace
If it is included in the namespace, it will also trigger
$(“div”).trigger(“click”);
Cancel or bind function
$('div ').bind('click', RecommandProduct);//Bind the RecommandProduct function to the div
$('div').unbind('click', RecommandProduct);//Cancel the RecommandProduct function