I have an html-template (will be used to design email template in app) at the client downloaded from ajax and is stored in a variable in javascript.
Now when I try to set my:
d开发者_如何学编程iv.innerHTML=var1;
it throws a very strange Syntax error.
when I tried the same with dojo:
dojo.place(var1, div, "replace");
same error!
The html does not have any script in it, no tables, but only divs and a few event maps, i.e. onblur="funcInactive(this)". The syntax is fine.
- What is the optimal way of setting innerHTML of a DIV?
Thanks
the HTML contained some attributes which were not valid, i.e.:
style="float: left"
instead of
style="float: left;"
and
onclick="javascript:this.onClick=''"
instead of
onclick="javascript:this.onClick='';"
Conclusion:
Internet Explorer complains it as syntax error when an innerHTML of an object is set with invalid (above example) html. Safari/FF/Chrome works ok.
The first argument of dojo.place can be a div or a DOM node, but the innerHTML receives only a string. Aparentemente you need to add slashes in var1, if contains scripts:
function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}
精彩评论