开发者

can I disable the button using like this in jquery?

$(this).closest("fieldset").find("input:not(:checkbox), select,textarea").attr('disabled', this.checked);  

with this I can Disable Input,select,textarea how to开发者_StackOverflow do with the button?

thanks


Your code works for me:

Try it out: http://jsfiddle.net/JzKdx/2/ (updated)

Were you having some specific issue?

HTML (updated to include submit button)

<fieldset>

    <input type='checkbox' /> Click me
    <br><br>
    <input type='text' />
    <select>
        <option>one</option>
    </select>
    <textarea>
        sometext
    </textarea>

    <input type='submit' />

</fieldset>

jQuery

$(':checkbox').change(function() {
    $(this).closest("fieldset")
        .find("input:not(:checkbox), select,textarea")
        .attr('disabled', this.checked);  
    });​


Not quite - as long as the disabled attribute is present, the control will be disabled. To re-enable the control, you have to remove the disabled attribute. Something like this:

var element = $(this).closest("fieldset").find("input:not(:checkbox), select,textarea");
if (this.checked) {
  element.attr('disabled', 'disabled');
} else {
  element.removeAttr('disabled');
}


Try this code

$(this).closest("fieldset").find("input:not(:checkbox), select,textarea,button").attr('disabled', this.checked);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜