admin管理员组文章数量:1201836
Is there a simple Javascript or JQuery way to make a textbox disabled WITHOUT using the attribute disabled?
We are using Handlebar.js and when a disabled field is found it skips the field when its serialized so we can't use the disabled attribute. Is there a way to make the textbox uneditable still? Perhaps with a focus or blur?
Is there a simple Javascript or JQuery way to make a textbox disabled WITHOUT using the attribute disabled?
We are using Handlebar.js and when a disabled field is found it skips the field when its serialized so we can't use the disabled attribute. Is there a way to make the textbox uneditable still? Perhaps with a focus or blur?
Share Improve this question asked Jul 18, 2014 at 8:33 cdubcdub 25.7k60 gold badges186 silver badges327 bronze badges 4- 3 Can you use Readonly? – Grim Commented Jul 18, 2014 at 8:35
- I'll test readonly now. Thanks – cdub Commented Jul 18, 2014 at 8:38
- Read more about stackoverflow.com/questions/2458595/disable-a-textbox-using-css – sajid Commented Jul 18, 2014 at 8:43
- The link isn't what was asked – cdub Commented Jul 18, 2014 at 8:48
3 Answers
Reset to default 16Use readonly
attribute instead :
$('#textBox').prop('readonly', true);
Use .attr() instead of .prop() if you're using jQuery < 1.9
directly add "readonly" attribute to the input element like this
Name: <input type="text" value="editing me is disabled" readonly>
It works like charm. No need of using jquery for that.
document.forms['formName']['inputName'].readOnly = true;
本文标签: javascriptDisable a text box without using disabledStack Overflow
版权声明:本文标题:javascript - Disable a text box without using disabled - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738637200a2104104.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论