Home >Web Front-end >JS Tutorial >Javascript sets the ReadOnly property of an object (sample code)_javascript skills

Javascript sets the ReadOnly property of an object (sample code)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:07:151010browse

The ReadOnly attribute in JS is rather strange. Create an object directly and assign the readonly attribute to the object. You cannot use the following method like in HTML:

Copy code The code is as follows:

var x=document.createElement("input");
x.type="text";
x.value="ttttt ";
x.id="xy";
x.readonly="readonly";

The object created in this way is not read-only. The correct way to write it is:
Copy the code The code is as follows:

var x=document.createElement( "input");
x.type="text";
x.value="ttttt";
x.id="xy";
x.readOnly=true;

You should pay attention to this when writing JS.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn