Str indicates the XMLRequest returned through ajax
/* Dynamically load css style */
Function loadStyle (str)
{
Var regExp_src =/<style. * src \ s * = \ s * ["'] [^"'] * ["']. *> [^ <>] * <\/style \ s *>/gi;
Var matchArray_src = str. match (regExp_src );
Alert (matchArray_src [0]);
If (matchArray_src ){
For (var I = 0; I <matchArray_src.length; I ++)
{Alert ("sss ");
Var str_temp = matchArray_src [I]. toString ();
Var regExp_src_temp =/<style. * src \ s * = \ s * ["'] ([^"'] *) ["']. *> [^ <>] * <\/style \ s *>/gi;
Str_temp.match (regExp_src_temp);/* here, the matching is used repeatedly. The $1 subexpression points to the current value, otherwise it will always be the last $1 value */
Var head = document. getElementsByTagName ('head') [0];
/* IE */
If (document. all ){
Alert ("IE ");
If (document. getElementsByTagName ('style') [0])
{
Var sty = document. getElementsByTagName ('style') [0]. innerHTML;
Alert (sty );
Var sty = document. getElementsByTagName ('style') [0]. innerHTML;
// I don't know how to obtain the current style label of IE. If you use getElementsByTagName, you can only use this policy to create a new one and add the previous style.
Var styleSheet = document. createStyleSheet ();
StyleSheet.css Text = sty + RegExp. $1;
}
Else
{
Var styleSheet = document. createStyleSheet ();
StyleSheet.css Text = "body {background: red ;}\ <br \>"
Alert ("finished ");
}
}
/* FIREFOX */
Else {
Var style;
If (document. getElementsByTagName ('style') [0])
{
Var sty = document. getElementsByTagName ('style') [0]. innerHTML;
Alert (sty );
Document. getElementsByTagName ('style') [0]. innerHTML = sty + RegExp. $1;
}
Else
Style = document. createElement ('style ');
Style. type = 'text/css ';
Style. innerHTML = RegExp. $1;
Head. appendChild (style );
Alert (RegExp. $1 );
}
}
}
}
/* Dynamically load a script with the src attribute */
Function loadScript_src (str ){
Var regExp_src =/<script. * src \ s * = \ s * ["'] [^"'] * ["']. *> [^ <>] * <\/script \ s *>/gi;
Var matchArray_src = str. match (regExp_src );
If (matchArray_src)
{
For (var I = 0; I <matchArray_src.length; I ++)
{
Var str_temp = matchArray_src [I]. toString ();
Var regExp_src_temp =/<script. * src \ s * = \ s * ["'] ([^"'] *) ["']. *> [^ <>] * <\/script \ s *>/gi;
Str_temp.match (regExp_src_temp );
Var head = document. getElementsByTagName ('head') [0];
Var script = document. createElement ('script ');
Script. type = 'text/javascript ';
Script. src = RegExp. $1;
Script. defer = "true ";
Head. appendChild (script );
Alert (RegExp. $1 );
}
}
}
/* Dynamically load the Script in innerHTML */
Function loadScript (str ){
Var regExp_function =/<script [^>] *> ([\ s \ S] *?) <\/Script [\ s] *>/gi;
Var matchArray_function = str. match (regExp_function );
If (matchArray_function ){
For (var I = 0; I <matchArray_function.length; I ++ ){
Var str_temp = matchArray_function [I]. toString (); // In fact, it is very convenient to search forward and backward using a regular expression, but javascript does not support it. Therefore, this policy can only be used.
Var regExp_function_temp =/<script [^>] *> ([\ s \ S] *?) <\/Script [\ s] *>/gi;
Var matchArray_temp = str_temp.match (regExp_function_temp );
Eval (RegExp. $1 );
}
}
}