Javascript设置对象的ReadOnly属性

在JS中ReadOnly属性比较奇怪,直接创建一个对象,给该对象赋值readonly属性不能够向HTML中一样使用下面的方式:
var x=document.createElement("input");
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;
这个平时写JS时候要注意。

posted @ 2007-06-04 23:51  深蓝  阅读(7017)  评论(3编辑  收藏  举报

我要啦免费统计