开发者

Issues with scripts when loading portion of page using Ajax

I'm loading portion of the page like described here: Spring MVC - Open new page without reload. Issue is that scripts executed at the beginning of page do not work for loaded html, because when scripts was executed html content was not loaded.

First script with issue is:

    $(document).ready(function() {
        $('#coclevel1').change(getLevel2);
        $('#coclevel2').change(getCocItems);
        ...
    });

coclevel1 and coclevel2 are html selects.

Second script is this script from here.

I'm developing Spring MVC 3.0 web application with Freemarker and JQuery.

How to apply scripts to l开发者_运维百科oaded html?


calling .change() only attaches a handler to current elements. Using .live() will bind a handler to all current and future elements.

$(document).ready(function() {
    $('#coclevel1').live('change', function(){getLevel2});
    $('#coclevel2').live('change', function(){getCocItems});
    ...
});

http://api.jquery.com/live/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜