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
Release: 2016-05-16 17:07:15
Original
1005 people have browsed it

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.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template