HTML Property Manipulation: Read, write
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>JS attribute operation</title> <Script> /*HTML Property Manipulation: Read, write property name: Property value: Read operation: Get, find element. Property name Write operations: Add, replace, modify elements. Property name = new Value*/window.onload= function(){ //get Element varOtext=document.getElementById ('Text1'); varOselect=document.getElementById ('Select1'); varobtn=document.getElementById ('button1'); //alert (obtn.value); ' Button ' //alert (otext.value); //alert (oselect.value); //String Connection //Otext.value Oselect.value //' Zhang San ' + ' beijing ' = ' Zhang San Beijing ' //' Zhang San ' + ' in ' + ' beijing ' = ' Zhang San in Beijing 'Obtn.onclick= function() {alert (Otext.value+ 'in the' +oselect.value); }; }; </Script></Head><Body> <inputtype= "text"ID= "Text1"> <Selectname=""ID= "Select1"> <optionvalue= "Beijing">Beijing</option> <optionvalue= "Shanghai">Shanghai</option> <optionvalue= "Guangzhou">Guangzhou</option> <optionvalue= "Shenzhen">Shenzhen</option> </Select> <inputtype= "button"ID= "Button1"value= "button" /></Body></HTML>
read operation: Get, find
Element. Property name
Write operations: Add, replace, modify
Element. property name = new value
innerHTML Operation:
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>InnerHTML</title></Head><Script> /*op.innerhtml = Read all the HTML code inside P op.innerhtml = 123; = = Replace all HTML code in P*/window.onload= function(){ //get Element varOtext=document.getElementById ('Text1'); varobtn=document.getElementById ('BTN1'); varOP=document.getElementById ('P'); Obtn.onclick= function() {op.innerhtml=Otext.value; Otext.value= "'; }; };</Script><Body> <inputtype= "text"ID= "Text1"> <inputtype= "button"value= "button"ID= "BTN1"> <PID= "P">This is a piece of text</P></Body></HTML>
op.innerhtml = Read all the HTML code inside P
op.innerhtml = 123;=> Replace all HTML code in P
JavaScript Basics-Property manipulation