开发者

Javascript event chaining / binding

I have a select list which has a function with a jQuery .post bound on the change() event.

<select id="location">
<option value="1"></option>
<option value="2"></option>
</select>

$('#location').change(location_change);

function location_change(){
    var url 开发者_C百科= '';
    $.post(url, callback);
}

What I would like to happen is other controls on the page can bind to the $.post callback function like it was an event, so after the location is changed the data is posted back to the server and once the post returns successfully, the subscriber events are fired.


You can do this with custom events. Make the post callback call a trigger('my_posted_event') and register any event handlers for that custom event using bind('my_posted_event').

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜