In fact, this article has nothing to do with Ajax, but because it is the problem encountered in the AJAX project. So .... innerHTML the script is not run when the assignment is done, you can extract the script using the regular expression, and then eval (script);
Sample code
<script type= "Text/javascript" >
<!--
function Load1 () {
var content= document.getelementbyid ("Content");
Alert ("Load1");
}
function Load2 () {
var content= document.getelementbyid ("Content");
Content.innerhtml= "Load2:<script>load1 ();<\/script>";
}
function Load3 () {
var content= document.getelementbyid ("Content");
Why JavaScript must be after a valid text label, but also talk about JS in IE and Firefox differences. In script block
If there is no valid text label before, IE will make an error. But Firefox works, God, save ie.
var str= "<a>javascript must be </a><script after a valid text label type=\" text/javascript\ ">load1 () <\/script > ";
CONTENT.INNERHTML=STR;
var regexp=/<script.*> (. *) <\/script>/gi;
if (Regexp.test (content.innerhtml)) {
eval (regexp.$1);
}
The following code is set to match multiple script blocks, but unfortunately it is not used in IE
can only run in Firefox, because enough, so did not write down interested can complete it, I JS did not learn it
var matcharray=str.match (REGEXP);
if (Matcharray) {
for (Var i=0;i<matcharray.length;i++) {
if (Regexp.test (Matcharray[i])) {
alert (regexp.$1);
// }
else{
Alert (Matcharray[i]);
// }
// }
//}
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.