开发者

Only Perform Action Once in jQuery

I am using jQuery UI and trying to disable all text boxes in a data group, but only do so once per loading of the tabs. Here is what I have so far:

$(function () {
        $("#tabs").tabs({
            cache: true,
            load: function (event, ui) {
                $(".data-group").one('load', function () {
                    $(this).find(':text').attr('disabled', 'disabled');
                });
            },
            select: function (event, ui) {
                // Do Stuff
            }
        });
    });

T开发者_运维问答he result is that I can enable the text boxes (via the interface), enter data, but the when I switch away from the tab and switch back, the value is in the text box (and validation messages are shown if there is an error in the data), but all boxes are disabled.

Suggestions for fixing this?


Try binding to the show event, something along the lines of 'if there is data in at least one of the text inputs then enable them', e.g.:

show: function(event, ui) {
    if($(".data-group").find(":text[value]").length) {
        $(".data-group").find(":text").removeAttr("disabled");
    }
}


I ended up solving this by caching the tabs so they only load once. Then, I enable the appropriate text boxes. From that point on, the user's actions determine if other boxes are enabled or disabled.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜