开发者

jQuery selector - input field

I'd like to enable the textbox when it is clicked. However, when I click the textb开发者_运维问答ox, nothing happens. I believe it is a problem with the jQuery selector. Why isn't this working?

<script>
    $(document).ready(function() {
        $(':input').click(function() {
            $(this).removeAttr('disabled');
        });
    });
</script>
<input type="text" value="123" disabled="disabled" />

Note: I tried both $('input') and $(':input') to select the textfield. Neither worked.


A disabled input isn't going to fire events. Try changing from disabled to readonly.


It has nothing to do with the selector you're using, but rather because, since the input element is disabled, the events for the input will not fire - see: http://www.jsfiddle.net/DvZDh/

<input type="text" value="123" disabled="disabled" />
<input type="text" value="123" />

The code works on the second input element, but not the first. A simple solution would probably be to use CSS to simulate the disabled state instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜