The compatibility of addRule in firefox is now a lot of ways to control html element styles using scripts.
For a single element, you can directly modify an element. style. display =... or element. className =... to modify multiple styles.
You can use a script to directly import the css file to modify the style of multiple elements.
The current project has such a requirement. It is required to change the style of all child nodes under a certain p, but not the style of p itself.
I did not want to leave the code below:
The Code is as follows:
Pp
Spanspan
Ttttt
Transfer
This code has been working very well until one day my colleague told me that my module crashed his browser.
I took a flashlight and looked for it again in the code of more than two thousand lines with a magnifier ..
I couldn't find the problem, and I had no doubt about the above Code.
The p id is directly read from the database, which is a number, for example
And so on.
I used to test the characters in ie6 and ff1.5 for the id,
The Code is as follows:
All such id settings can be used
Document. getElementById ("A shun ")
Document. getElementById ("??? "),
Document. getElementById ("-1 "),
There is no problem with reading, not to mention pure numbers.
Finally, after repeated debugging, find the culprit addRule.
Document. styleSheets [0]. addRule ("# a1 *", "background-color: red ")
Document. styleSheets [0]. addRule ("#123 *", "background-color: red ")
No problems
The following line of code will let ie die. The memory and virtual memory have been skyrocketing. I have 512 of the memory, and all of a sudden xp prompts that the virtual memory is not enough.
Document. styleSheets [0]. addRule ("#-1 *", "background-color: red ");
Similarly, in ff1.5, the function will fail, but will not crash.
Summary:
1. Ie and ff are quite tolerant of id values. IDS can be almost any character, Chinese, English, letters, numbers, negative numbers, and special characters.
2. However, in the addRule function, if the id is negative, both ie and ff will fail and ie will crash.
Appendix:
Compatibility of addRule in ff
The Code is as follows:
Pp
Spanspan
Ttttt
Script
Function f (){
Var rule = "# a1 * {background-color: red }";
Var index.html document.stylesheets%0%.css Rules. length;
Document. styleSheets [0]. insertRule (rule, index );
}
Script
Transfer