关于JS如何实现表单的readonly

来源:百度知道 编辑:UC知道 时间:2024/06/28 01:50:30
就是通过JS来实现表单的哪个<input>为只读,这样可以吗?谢谢各位大虾了!!!

当让可以

function check(){
var txtN = document.getElementById("test");
txtN.setAttribute("readonly",true,0);
}

setAttribute 这个方法一定要注意,有三个参数
object.setAttribute(sName, vValue [, iFlags])

last arg
iFlags: Optional. Integer that specifies one the following flags: 0 When the attribute is set, it overwrites any attributes with the same name, regardless of their case.
1 Default. The case of the attribute that you set is respected when it is set on the object.

是要全部只读,还是仅让表单中的标签只读啊
每个标签都有它自己的属性即ReadOnly,只要将其设置为true即可.
<input type="text" id="t1" Readonly="true"/>这样即可.
如果是select标签,则设置他的disabled属性为true
<select id="s1" disabled="true/>

<input type="text" readonly>

只读的那只是信息,用个table或div 等元素不就可以做到了吗?为什么一定要用表单呢?
表单是为了方便与用户交互的。一个只读的表单,多少感觉这是没事找事。。。