将文本框设置为只读,在 Javascript 中不起作用
Setting textbox to readonly not working in Javascript
我已经尝试了以下代码将文本框属性设置为只读,但它们都不起作用。谁能告诉我怎么做?
document.getElementById("phone_numbers").disabled=true;
document.getElementById("phone_numbers").readonly=true;
document.getElementById("phone_numbers").readOnly=true;
document.getElementById("phone_numbers").readOnly=readOnly;
document.getElementById("phone_numbers").readOnly=readonly;
document.getElementById("phone_numbers").readonly=readonly;
document.getElementById("phone_numbers").readonly=readOnly;
document.getElementById("phone_numbers").setAttribute('readonly', 'readonly');
document.getElementById("phone_numbers").setAttribute("readonly", "true");
编辑
当我编辑我的问题以写更多细节时,我意识到问题是什么。我犯了一个愚蠢的错误。这是我最初的HTML代码。
<input name="phone_numbers">
我把它改成了
<input id="phone_numbers">
它奏效了!
顺便说一下,以下是实际工作的功能。
document.getElementById("phone_numbers").disabled=true;
document.getElementById("phone_numbers").readOnly=true;
document.getElementById("phone_numbers").setAttribute('readonly', 'readonly');
document.getElementById("phone_numbers").setAttribute("readonly", "true");
你的第三行对我有用:JSFiddle
.HTML
<input id="phone_numbers" type="textbox"></input>
爪哇语
document.getElementById("phone_numbers").readOnly=true;
如果textbox
是服务器端,则使用document.getElementById("<%= phone_numbers.ClientId %>")
访问它。
相关文章:
- 幻灯片滚动javascript不起作用
- 当我在浏览器中打开HTML文件时,javascript不起作用
- 来自MDN的循环示例的JavaScript不起作用
- 在IE中切换javascript不起作用的复选框
- 在SVG中创建带有外来对象的文本区域的Javascript不起作用
- 寻呼<李>javascript不起作用
- 想制作一个基于URL的音频播放器,但Javascript不起作用
- 从Android设备浏览时Javascript不起作用
- 在 Javascript 不起作用的情况下为数字添加逗号
- 获取PHP变量的JavaScript不起作用
- 有些JavaScript不起作用
- 保存HTML文件后,Javascript不起作用
- onClick javascript不起作用
- 在Wicket ModalWindow中使用Panel时,HTML中的Javascript不起作用
- Jquery顶部的两行Javascript不起作用
- 当我通过Node服务器提供HTML时,为什么我的页面Javascript不起作用
- Javascript不起作用,但当放置断点并从chrome调试器工具中单击文件时,它可以正常工作
- 为不同的屏幕分辨率加载css样式的Javascript不起作用
- 在IE9中javascript不起作用,但在打开控制台后它就起作用了
- 为什么Javascript不起作用