最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - change innerHTML to form - Stack Overflow

programmeradmin0浏览0评论

Today I was trying to make the innerHTML of a DIV change to a FORM, 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?

Today I was trying to make the innerHTML of a DIV change to a FORM, 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?

Share Improve this question edited Oct 8, 2011 at 8:51 JohnP 50k13 gold badges112 silver badges141 bronze badges asked Oct 8, 2011 at 8:25 givawaygivaway 235 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

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>';
发布评论

评论列表(0)

  1. 暂无评论