Monday 15 September 2014

html - Create an input field using pure Javascript -


I am trying to create such an element with JS:

  & lt ; Input type = "text" value = "default" & gt;   

To do this, I tried this code:

  var mi = document.createElement ("input"); But when I run it in Chrome Dev Dev itself, it only creates this element:  
  & lt; Input type = "text" & gt;   

What am I missing?

code> var m = document. CreateElement ("Input"); Mi.setAttribute ('type', 'text'); Mi.setAttribute ('value', 'default');

You can now see

  New XMLSerializer (). SerializeToString (mi); // "& lt; input type =" article "value =" default "& gt;"   

In your example, & lt; Input & gt; Price still displayed by will be default , it is not set as the attribute only.

Further note if the user value is of & lt; Input & gt; , such as the type, attribute value will not be changed, but the value property settings will still change it. Again, this is because attribute is different from property .

No comments:

Post a Comment