Home >Web Front-end >JS Tutorial >JavaScript enhanced custom callback example_javascript skills

JavaScript enhanced custom callback example_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:21:571283browse

html:

Copy code The code is as follows:



js:
Copy code code As follows:

$().ready(function(){
$("select").unbind("clickMe");
//Pass a json format object, this There are name, age, callback in json, which can be accessed using objJSON. attribute name
$("select").bind("clickMe", function(event,objJSON){
alert(objJSON. name);
alert(objJSON.age);
objJSON.callback();
});

$("select").unbind("change");
$("select").bind("change",function(){
//The parameter of the event trigger is an object in json format
$(this).trigger("clickMe",{
name:'xxc',
age:20,
callback:function(){
alert("callback function");
}
});
}) ;
});
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