admin管理员组文章数量:1331671
I'd like to create a callback on a simple function.
I have this function which is called on button click:
function main(){ };
So I'd like main()
, when its done to call this:
function test(){ }
I'd like to create a callback on a simple function.
I have this function which is called on button click:
function main(){ };
So I'd like main()
, when its done to call this:
function test(){ }
Share
edited Dec 15, 2011 at 7:00
Bhesh Gurung
51k23 gold badges95 silver badges143 bronze badges
asked Dec 15, 2011 at 6:55
jQuerybeastjQuerybeast
14.5k39 gold badges119 silver badges198 bronze badges
3 Answers
Reset to default 4function main(callback) {
// ... do your thing
callback();
}
main(function(){
alert('this is the callback speaking');
});
if the main() function not use ajax,you can use:
function main(callback) {
// ... do your thing
callback();
}
function test(){}
eg:
<input type="button" onclick="main(test);"/>
if the main() function use ajax,you can call test() in plete function like this:
function main(callback){
$.ajax({
...
plete: function(XMLHttpRequest, textStatus){
callback();
},
...
});
}
function test(){
...
}
eg:
<input type="button" onclick="main(test);" value="test"/>
As i understood its simple,Sorry if i am not in the point.
function main() {
// ... do your thing
test();
}
function test() {
// ... do your thing in test
}
本文标签: javascriptjQuery Create CallbackStack Overflow
版权声明:本文标题:javascript - jQuery Create Callback - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742264371a2443108.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论