Usage:
1 < ID= "Test">2 <style= "Color:red">test1</span> test23 </div>
In JS, you can use:
test.innerhtml:
That is, the entire contents of the object from its starting position to the terminating position, including the HTML tag.
The value of test.innerhtml in the example above is "<span style=" color:red ">test1</span> test2".
Test.innertext:
The content from the starting position to the terminating position, but it removes the HTML tag
The value of text.innertest in the example above is "Test1 test2", where the span tag is removed.
Test.outerhtml:
In addition to the entire contents of the innerHTML, the object label itself is included.
The value of text.outerhtml in the above example is <div id= "test" ><span style= "color:red" >test1</span> test2</div>
Complete Example:
1 <DivID= "Test">2 <spanstyle= "Color:red">Test1</span>test23 </Div>4 5 <ahref= "Javascript:alert (test.innerhtml)">innerHTML Content</a>6 <ahref= "Javascript:alert (test.innertext)">inerhtml Content</a>7 <ahref= "Javascript:alert (test.outerhtml)">outerHTML Content</a>
Special Note:
innerHTML is a standard-compliant attribute, and innertext only works with Internet Explorer, so use innerHTML as much as possible, and less innertext, if you want to output content that does not contain HTML tags, You can use innerHTML to get content that contains HTML tags, and then use regular expressions to remove the HTML tags, and here's a simple example of the standard:
<a href= "Javascript:alert (document.getElementById (' Test '). Innerhtml.replace (/<.+?>/gim, '))" > No HTML, Meet the Standards </a>
--------------------------------------------------------------------------------------------------------------- ----------------
1 <HTML>2 <Head></Head>3 <Framesetframeborder= "Yes"frameborder= "1"rows= "40%,*">4 <Framename= "Top"src= "1.html">5 <Framename= "Bottom"src= "2.html">6 </Frameset>7 </HTML>8 9 <HTML>Ten <Head> One <Scriptlanguage= "JavaScript"> A functionInit () - { - varAAA=parent.window.frames[0].document.body.innerhtml; the alert (AAA); - } - </Script> - </Head> + <Body> - <PAlign= "Center">Nothing</P> + <PAlign= "Center"><inputtype= "button"onclick= "init ()"; value= "click"></P> A </Body> at </HTML> - - <HTML> - <Center>Car Real Estate Woman</Center> - </HTML>
Source: http://www.phpweblog.net/kiyone/archive/2007/05/17/1206.html Thanks to the author for sharing
About the difference between innerHTML and innertext,outerhtml (turn)