开发者

jQuery: how does one disable everything inside a div? but still keep everything visible?

The goal is to disable all the links, when one is clicked, and then disable all the links until the server sends an undisable command (using a similar method that would be used to disable).

So, since all the links are in one containing div, I figure I could just temporarily disable that.

How would I go about doing开发者_如何转开发 that?


If you just want to disable the default link behaviour, you can use a combination of delegate and event.preventDefault:

$('#container').delegate('a', 'click', function(e) {
    if (linksDisabled) {
        e.preventDefault();
    }
});

You can then set linksDisabled (in a parent scope) to true or false in your other event handlers as appropriate.

If these links are doing Javascripty things, it's a bit trickier. It would probably be easiest to put the if (linksDisabled) check in each event handler.


Try this:

$("#YOUR_DIV a").click(function(){
 return false;
})
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜