【问题标题】:How can I disable one button of a jQuery-UI buttonset?如何禁用 jQuery-UI 按钮集中的一个按钮?
【发布时间】:2012-10-23 16:08:27
【问题描述】:

这里的例子:

http://jsfiddle.net/UVHtu/19/

我需要填空:

HTML:

<div id="options">
    <input type="radio" id="op_a" name="op" value="a" />
    <label for="op_a">Option A</label>
    <input type="radio" id="op_b" name="op" value="b" />
    <label for="op_b">Option B</label>
    <input type="radio" id="op_c" name="op" value="c" />
    <label for="op_c">Option C</label>
</div>
<input type="button" id="disable_button" value="Disable Option B" />
​

JavaScript:

$("#options").buttonset();

$("#disable_button").click(function(){
    // What goes here to disable option B?
});

【问题讨论】:

    标签: javascript jquery jquery-ui jquery-ui-button jqueryi-ui-buttonset


    【解决方案1】:
    $("#options").buttonset();
    
    $("#disable_button").click(function(){
        // What goes here?
        $('#op_b').attr("disabled", "disabled");
        $("#options").buttonset("refresh");
    });
    

    【讨论】:

    • 非常简洁的答案,我想我会使用 jQuery 选择器代替 document.getElementById()attr("disabled", "disabled") 代替 disabled = true
    • 在这种情况下,我建议使用prop 而不是attrstackoverflow.com/questions/5874652/prop-vs-attr
    • 好点。我还不是 100% 这个站点使用的 jQuery 版本支持 prop()。但我确实需要养成这个习惯......
    猜你喜欢
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    相关资源
    最近更新 更多