开发者

How to disable an input with jQuery Validation Plugin

This should be really simple but I can't get it to work, how do I disable and add a class to an input? Let's say I've got an input field with id = name, this is how far I got,

$("input#name").attr("disabled");

What am I doing wrong here? Any help would be开发者_JAVA百科 greatly appreciated, thanks in advance!


You need to give .attr() a second parameter (the value to set, otherwise it gets the value), true in this case ("disabled" works too, but a boolean is desirable for a few reasons here):

$("input#name").attr("disabled", true).addClass('myClass');

.addClass() then adds that class to the element.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜