在JS中ReadOnly属性比较奇怪,直接创建一个对象,给该对象赋值readonly属性不能够向HTML中一样使用下面的方式:
var
x
=
document.createElement(
"
input
"
);
x.type = " text " ;
x.value = " ttttt " ;
x.id = " xy " ;
x.readonly = " readonly " ;
这样创建的对象并不是只读的。正确的写法是:
x.type = " text " ;
x.value = " ttttt " ;
x.id = " xy " ;
x.readonly = " readonly " ;
var
x
=
document.createElement(
"
input
"
);
x.type = " text " ;
x.value = " ttttt " ;
x.id = " xy " ;
x.readOnly = true ;
x.type = " text " ;
x.value = " ttttt " ;
x.id = " xy " ;
x.readOnly = true ;
这个平时写JS时候要注意。
本文转自深蓝居博客园博客,原文链接http://www.cnblogs.com/studyzy/archive/2007/06/04/771354.html:,如需转载请自行联系原作者