我想将一个变量从php传输到javascript,但是在开头和结尾都要继续获得额外的quatation标记。我做错了什么,有更好的方法吗?
$textForm = '<form method="post" action="upload.php" name="truth">
<br />
Tittle:<br /><input type="text" name="title" size="40" /> <br /><br />
Author:<br /><input type="text" name="author" size="40" /> <br /><br /><br />
Text:<br /><textarea name="story" cols="90" rows="24" wrap="physical">Input text here.</textarea>
<br /><input type="submit" value="upload" />
<form>';
<script type = "text/javascript">
function showTextForm() {
var form1 = '<?php print json_encode($textForm1); ?>'
</script>
答案 0 :(得分:1)
认为你可以做到:
<script type = "text/javascript">
function showTextForm() {
var form1 = <?=json_encode($textForm1); ?>;
</script>