JavaScript overwrites the document. createElement Method

Source: Internet
Author: User

Recently encountered a problem in the project, there is a asp.net web program can only run in IE7, now xp are eliminated, everyone uses IE8-IE11, so this web app also needs to upgrade to adapt to all IE versions. According to the incompatibility of IE, the document. createElement method is called, for example:

Function addStyleNo (value, cannotDel ){
If (! Value ){
Value = '';
}
Var tb = $ ('tbodystyle ');
Var tr = tb. insertRow ();
Var td1 = tr. insertCell ();
Td1.style. width = '20px ';
Td1.style. height = '20px ';
If (! CannotDel ){
Var imgDel = document. createElement ("");
Td1.appendChild (imgDel );
}

Var td2 = tr. insertCell ();
Td2.style. height = '20px ';
Var txt = document. createElement ("");
Td2.appendChild (txt );

}

There are too many js files in this system, and you are not familiar with the business of this system. I used to replace this document. createElement with jquery,

Var imgDel = jq ("") [0];

Var txt = jq ("") [0];

Later I found that there were too many places to change. So think about whether there is a simple method, and finally point the finger to overwrite the implementation of the document. createElement method.

Document. createEl = document. createElement;
Document. createElement = function (obj ){
If (obj. toString (). indexOf ("<")>-1 ){
Return jq (obj) [0];
}
Else {
Return document. createEl (obj );
}
}

No exceptions have been found in ie.

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.