Home > Web Front-end > JS Tutorial > A special case of innerHTML execution under Mozilla Firefox and Opera. _javascript skills

A special case of innerHTML execution under Mozilla Firefox and Opera. _javascript skills

WBOY
Release: 2016-05-16 19:21:56
Original
1138 people have browsed it

This is a question I saw on the CSDN forum. I usually don't pay attention to it, or I don't use it in this way. Look at the code


[Ctrl A to select all Note: If you need to introduce external Js, you need to refresh to execute
]


Isn't that the expected result? The execution situation under Opera is also the same as that under Firefox. You can try to run it under Opera and you will understand.

What if we can get the results we expected? I tried to use the __defineGetter__ method to get all innerHTML under Mozilla, but here it gave me some tips. For example:

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
The above code Although it cannot achieve the expected purpose, it is necessary to know that the value of the attribute must be obtained, so I tried to use the following method.
[Ctrl A to select all Note:
If you need to introduce external Js, you need to refresh to execute
]

This method was successful, which means that innerHTML under Mozilla obtains its innerHTML by traversing the tagName and attrubutes of all nodes of the element. Therefore, the innerHTML in our first example cannot get the modified value.
<script> var foo = function() { var $ = function() { return document.getElementById(arguments[0]); } $("d2").innerHTML = $("d1").innerHTML; } //]]> </script>At the same time, this trick can also be used in Opera. It also proves that innerHTML under Opera also obtains its innerHTML by traversing the tagName and attrubutes of all nodes of the element. Is this the standard in w3c? I haven't had time to check the w3c information yet, so I can't say whether it's a coincidence between Opera and Mozilla, or whether it's a design that's more comfortable for developers under IE.
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template