0

Here's what I'm using

    $(document).ready(function() {
    $(".accept").change(function () {
        if ($(this).val() == "0") {
            $(".generateBtn").addClass("disable");
        } else {
           $(".generateBtn").remove("disable");
        }
    });
});

It works after you change the value, but how do I add the style to the div on load to disable?

Do I simpily juse call

$(".generateBtn").addClass("disable");

Or is there a more elegant technique

4

1 回答 1

0

只是触发一个变化怎么样?

$(document).ready(function() {
    $(".accept").on('change', function () {
        if ($(this).val() == "0") {
            $(".generateBtn").addClass("disable");
        } else {
           $(".generateBtn").remove("disable");
        }
    }).trigger('change');
});

我猜你打算写removeClass而不是remove,如果是这样:

$(document).ready(function() {
    $(".accept").on('change', function () {
        $(".generateBtn").toggleClass('disable', this.value=='0');
    }).trigger('change');
});
于 2013-11-10T23:02:15.853 回答