change innerHTML to form
Today I was trying to make the innerHTML of a DIV change to a FO开发者_运维问答RM, but I keep getting the following error Uncaught SyntaxError: Unexpected token ILLEGAL
. I've modified the code to say changed
and it works fine, but if I try to change it to the following code it gives me that error.
document.getElementById(div).innerHTML = '<form method="post" action="all.php?f=mu">
<input name="afterurl" type="hidden" value="<?php $url ?>" />
<input name="preurl" type="hidden" value="" />
<input name="newurl" type="text" value="" />
</form>';
Any idea how I can get it to work?
You can't have text span multiple lines like that in JS. Use string concatenation or put it into one line
document.getElementById(div).innerHTML = '<form method="post" action="all.php?f=mu">' +
'<input name="afterurl" type="hidden" value="<?php $url ?>" />' +
'<input name="preurl" type="hidden" value="" />' +
'<input name="newurl" type="text" value="" />' +
'</form>';
精彩评论