Javascript sets the sample code for the ReadOnly attribute of the object

  • 2020-03-30 01:04:59
  • OfStack

In JS, the ReadOnly attribute is a bit strange. If you directly create an object and assign the ReadOnly attribute to the object, you cannot use the following method as in HTML:

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

Objects created this way are not read-only. The correct way to write it is:

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

This usually write JS to pay attention to.

Related articles: