Ajax --- some differences between IE and Firefox scripts

Source: Internet
Author: User
Ajax ------- some differences between IE and Firefox scripts

When Ajax is used for development, it is inevitable to encounter different browser implementations. The following is a summary of aoiumi.

1: innertext
Supported by IE, not supported by Firefox
Solution: Use innerhtml and both browsers to recognize innerhtml

2: Document. createelement
Document. appendchild
Insert rows into the table
Supported by Firefox, not supported by IE
Solution: Insert rows into the tbody instead of the table.

3: setattribute ('style', 'color: red ;')
Supported by Firefox (except IE, supported by all browsers now), not by IE
Solution: Do not use setattribute ('style', 'color: red ')
Use object.style.css text = 'color: red; '(this is also an exception)
The best way is to use the above methods.
4: Class
Setattribute ('class', 'styleclass ')
Supported by Firefox and not supported by IE (if the attribute is specified as class, ie will not set the class attribute of the element. On the contrary, ie will automatically identify the classname attribute only when setattribute is used)
Solution:
Setattribute ('class', 'styleclass ')
Setattribute ('classname', 'styleclass ')
Use both

5: Use setattribute to set events
VaR OBJ = Document. getelementbyid ('objid ');
OBJ. setattribute ('onclick', 'funcitonname ();');
Supported by Firefox, not supported by IE
Solution:
In IE, you must use the vertex method to reference the required event handler and assign the anonymous Function
As follows:
VaR OBJ = Document. getelementbyid ('objid ');
OBJ. onclick = function () {fucntionname ();};
All browsers support this method.

6. Create a radio button.
Browsers other than IE
VaR rdo = Document. createelement ('input ');
Rdo. setattribute ('type', 'Radio ');
Rdo. setattribute ('name', 'radiobtn ');
Rdo. setattribute ('value', 'checked ');

IE:
VaR rdo = Document. createelement ("<input type = 'Radio 'name = 'radiobtn' value = 'checked'> ";
Solution:
The difference is different from the previous one. This time is completely different, so we cannot find a common solution, so only if-else is available.
Fortunately, ie can identify the uniqueid attribute of the document. other browsers cannot recognize this attribute. Solve the problem.

0: common skills
When dynamically creating Input elements, we usually add them first and set the type. This may cause errors.

Good Habit: var BTN = Document. createelement ('input ');
BTN. setattribut ('type', 'click ');
Document. getelementbyid ('formid '). appendchild (BTN );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.