CopyCode The Code is as follows: <Div id = "test">
<A href = "#"> test </a>
</Div>
<Div id = "result"> </div>
<SCRIPT type = "text/JavaScript">
(Function (){
VaR test = Document. getelementbyid ('test ');
Alert (test. innerhtml );
VaR result = Document. getelementbyid ('result ');
Result. innerhtml = test. innerhtml;
Alert (result. innerhtml)
})();
</SCRIPT>
The result shows that the href value of element a in result. innerhtml popped up for the second time in IE6 and IE7 is an absolute path.
In fact, people have encountered these problems early (thanks to the materials provided by yuber ):
Getattribute ("href") is always absolute
Getattribute href bug
Above Article The processing scheme has been mentioned, that is, using the getattribute ('href ', 2) method in IE. Microsoft has extended the second parameter for this method, which can be set to 0, 1, and 2. If it is set to 2, the original attribute value is returned.
Script correction: Copy code The Code is as follows: (function (){
VaR test = Document. getelementbyid ('test ');
Alert (test. innerhtml );
VaR result = Document. getelementbyid ('result ');
Result. innerhtml = test. innerhtml;
If (/* @ cc_on! @ */0) {// If IE
VaR links1 = test. getelementsbytagname ('A ');
VaR links2 = result. getelementsbytagname ('A ');
For (VAR I = 0, Len = links1.length; I <Len; ++ I ){
Links2 [I]. href = links1 [I]. getattribute ('href ', 2 );
}
}
Alert (result. innerhtml );
})();
An interesting bug found by hedger Wang was found during the search for this problem: when the new href attribute value is reset in IE, if the link text contains "http: // "or" @ ", the innerhtml is displayed incorrectly and is displayed as the href attribute.
Solution (shref is the new href value to be set ):Copy codeThe Code is as follows: shref = 'HTTP: // www.hedgerwow.com ';
VaR ismsie =/* @ cc_on! @ */False;
If (ismsie ){
Shref = ''+ shref; // Add extra space before the new href
};
Details: Internet Explorer might reset anchor's innerhtml incorrectly when a new "href" is assigned