jquery dynamic loading CSS style browser compatibility processing

Source: Internet
Author: User
Tags javascript appendchild

A more serious bug: Under IE6, IE7, the validation hint's style file does not load in.
So this morning for this bug, tested several times, still not, finally found that the original is because of the jquery method of dynamic loading CSS tutorial style files, there are compatibility issues.

The code that originally dynamically loaded the CSS file in the Jquery.skygqcheckajaxform.1.3.js file is this:

Load CSS Styles
if ($ ("link[href$=valid.css]"). Length = = 0) {
$('
<link href= "' +settings.root+ ' css/valid.css" Type=text/css rel=stylesheet> "). Appendto (" Head ");
}

In this way under Firefox and IE8 is not a problem ~ but under IE6 and IE7, the style file does not work, and then made the following changes:

Load CSS Styles

if ($ ("link[href$=valid.css]"). Length = = 0) {
var css_href = settings.root+ ' css/valid.css ';
var Styletag = document.createelement ("link");
Styletag.setattribute (' type ', ' text/css ');
Styletag.setattribute (' rel ', ' stylesheet ');
Styletag.setattribute (' href ', css_href);
$ ("head") [0].appendchild (Styletag);
}

The above code creates elements with native Web page effects, and finally adds the dynamically created link element to the head element using native JavaScript appendchild methods.

After testing, the above code with compatible IE6, IE7, IE8, Firefox browser, the other browser does not test ~ If someone found that there are problems in other browsers, please tell me

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.