]
IE7.0, Firefox2. 0. Opera9.0 passed the test
Welcome everyone to give advice and criticism
I have been studying Js some time ago. There are many articles on the Internet about compatible browsers. I found a few for you:
http: //blog.csdn.net/zqian1987/archive/2008/03/02/2140055.aspx
http://www.cnblogs.com/jacklong/archive/2008/01/10/1033954.html
The following is about some of my experiences during this period, mainly in terms of compatibility with IE and FireFox. The versions before Opera 9.0 seem to not support many things, so I will not introduce them for the time being. The versions after Opera 9.0 are incompatible with Javascript interpretation. FireFox is closer.
What I introduced are some details, focusing on some uncommon situations. I will continue to add new ones as I think of them:
1. Create an Element. The common writing method is createElement("div")
You can also write createElement("
") in IE, but Firefox does not recognize it.
2. The concepts of width and height in IE are different from those in Firefox. IE Medium width=width 2*borderWidth 2*Padding in FireFox
See: http://help.powereasy.net/Template/WEB/1557.html
3. Dynamically add css code
cssStr = " p { color:#FF0000;} a { font-size:9pt;}";
var style = win.document.createStyleSheet();
style.cssText = cssStr;FireFox: Copy content to clipboard code :
cssStr = "p { color:#FF0000;} a { font-size:9pt;}";
var style = win.document.createElement("style");
style.type = "text/css";
style.innerHTML = cssStr;
win.document.getElementsByTagName("HEAD").item(0).appendChild(style); 4. Add rows or columns to the table at the end, The general writing method insertRow(-1), insertCell(-1)
In IE, insertRow(), insertCell() can also be written like this, but Firefox does not recognize it.
5. Warning dialog box alert(), there is no such thing when writing in IE The default parameter is an empty string. In Firefox, the parameter must be entered. To pass an empty parameter, it must be written as alert("");
6. The value assigned to element.style.width must be written as 24px. If only the number 24 is written, FireFox will not recognize it, but it can be found in IE
7. Use Element and bind it to onclick, onmouseover, onmousedown, onmouseout and other events
element.onclick = function() { alert("hello kitty" ); }; When
, please note that
use appendChild when adding this element to the parent element. Do not use innerHTML operation in the parent element, which will invalidate the event