Recently in the framework of writing the project, write a Jquerymessagebox class to use dialog () in the jquery UI to display the message box, in order to make the method convenient to call, then added the automatic Judgment page joins the Ui.js and Ui.css, the code is as follows:
[JavaScript]View Plaincopyprint?
- If the ui.js is not included, the reference
- if ($ (' script[src$= "" "Jquery-ui-1.8.11.custom.min.js" "]"). Length = = 0) {{
- $ ("" <script src='/js/jquery-ui-1.8.11.custom.min.js ' type=' text/javascript '/> '). AppendTo ( ' head ');
- }}
- If the CSS is not loaded, the load
- if ($ (' link[ref$= "" "Jquery-ui-1.8.14.custom.css" "]"). Length = = 0) {{
- $ (' <link href= ' ""/css/jquery-ui-1.8.14.custom.css "" rel= "" Stylesheet "" type= "" Text/css ""/> "). AppendTo ( ' head ');
- Dialog () script
- }}
But the CSS code will not be loaded immediately, so when the display dialog will not have the style (under IE9, because in the IE9 under the CSS even after downloading, will also redraw the page elements, and IE8 will not). To solve this problem, you can use Ajax, when the CSS is loaded, and then display dialog, so that you can show the style, the code is as follows:
[JavaScript]View Plaincopyprint?
- if ($ (' link[ref$= "" "Jquery-ui-1.8.14.custom.css" "]"). Length = = 0) {
- $.ajax ({
- URL: '/css/jquery-ui-1.8.14.custom.css ',
- Success: function (data) {
- //Create a STYLE element and append it to the head
- //Replace the path where images
- $ (' <style type= ' text/css ' > ' + data.replace (/url\ (images/g, ' url (/css/images ') + ' </style> '). AppendTo (' head ');
- //dialog () script;
- }
- });
- }
- else {
- //dialog () script;
- }
Follow-up code after the CSS has finished loading