开发者

Window in jquery

I call window:

$(function(){
$('.link').live('click开发者_StackOverflow社区', function(){
    var perf = $(this).attr('id');
    var action = 'develop';
    var user_id=$('#user_id').val();
    var dataString = 'action='+action+'&perf='+perf+'&user='+user_id;

    $.ajax({
        type: "POST",
        url: "test.php",
        data: dataString,
        cache: false,
        success: function(html){
            $("#work-window").append(html);
        }
    });
});
});

Result in html:

<div id="div-add">
<span id="link-close">`[close]`</div>
</div>

Code for close window when you click on link (#link-close):

$('#link-close').live('click', function(){
    $('#div-add').css('visibility', 'hidden');
});

But here have bug. Window closing only one times. When you reopen the window and trying close, then this is not close. As remove this problem?

  • How to do that window closing when you click on outside.

Please help me :) And sorry for my English.


You have problem with multiply instanses of elements with the same ids on a page. So when you're executing closing code the second time:

$('#div-add').css('visibility', 'hidden');

it selects the fist one "#div-add" element and do nothing to other instances.

To solve this problem you should remove '#div-add' from page on close (or rewrite your code to use class selector instead of id).

$('#link-close').live('click', function(){
    $('#div-add').remove();
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜