开发者

Adding div using ajax and jQuery

How would I create a div that when clicked sends an ajax call to a jsp page to replace the content of the div th开发者_StackOverflow中文版at has been clicked while adding a css class to the changed div?


<div id="foo"></div>

and then:

$('#foo').live('click', function() {
    $(this).load('/bar.jsp', function() {
        $('#foo').addClass('foobar');
    });
});


the div in the view:

<div id="a" class="a" onclick="clickFunc()">...</div>

the javascript function:

function clickFunc() {$("#a").load("whatever.jsp"); $("#a").addClass("newClass");}

Hope this is what your looking for.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜