1 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"2 "Http://www.w3.org/TR/html4/loose.dtd">3 <HTML>4 <Head>5 <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312">6 <title>The difference between innerHTML and innertext</title>7 <Scripttype= "Text/javascript">8 9 functiontestinnerhtml () {Ten One varDiv1=document.getElementById ("Div1"); A - //innerHTML is to execute the following string as HTML code - div1.innerhtml="<font color= ' Red ' >hello1</font>"; the - } - - functionTestinnertext () { + - varDiv2=document.getElementById ("Div2"); + A //innertext is to treat the following string as a string, even if it is followed by an HTML statement that is executed as a string at //div2.innertext= "<font color= ' Red ' >helllo2</font>" - - //textcontent and innertext function similar, but innertext Firefox browser does not support, Textcontent,ie browser does not support; Textcontent and innertext Google browser support - div2.textcontent="<font color= ' Red ' >hello2</font>"; - - } in - </Script> to </Head> + - <Body> the * <inputtype= "button"value= "InnerHTML"onclick= "testinnerhtml ()"/> $ <DivID= "Div1"></Div>Panax Notoginseng <inputtype= "button"value= "InnerText"onclick= "Testinnertext ()"/> - <DivID= "Div2"></Div> the </Body> + </HTML>
The difference between 17.innerHTML and innertext