0

我想将一个变量从 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>
4

1 回答 1

1

认为你可以简单地做:

<script type = "text/javascript">
function showTextForm() {

var form1 = <?=json_encode($textForm1); ?>;
</script>
于 2012-11-12T15:27:03.670 回答