Talk about createElement events in javascript

  • 2020-03-30 04:29:37
  • OfStack

CreateElement is the concept of creating child nodes, or child elements, in HTML using the W3C DOM image model


 <script>
   window.onload = function () {
   var input  = document.createElement('input');
   var button = document.createElement('input');
   input.type ='text'; 
   input.id= 'text';
   input.value ='1';
   button.type='button';
   button.value =' One by one to add ';
   button.style.width = '40px';
   button.style.height = '23px';
   document.body.appendChild(input);
   document.body.appendChild(button);
   button.onclick = function(){
      var value = input.value;
      input.value = value * 1 + 1;
   }
  }
 </script>

  Note: value is actually a character, if input. Value =value*1+1; For input. Value = value + 1; The result will be 111111, which is incremented by 1, so the value*1 will be able to convert the value to Int.

Conclusion:

To finally resolve the compatibility issue with the createElement method, it is important to note that the browser still USES the W3C specification's standard approach for non-internet explorer to use its unique method of passing in a legitimate HTML code string as a parameter for createElement.


Related articles: