我有一个some.php和一些php处理,它也有:
<form action="" method="post">
<input type="text" name="name" value="bleh" />
<input type="submit" name="submit" value="submit" />
</form>
我还有另一个带有jquery脚本的php:
<h1>form goes here</h1>
<script>
$("h1").replaceWith(" <?php include ('some.php'); ?> ");
</script>
问题是…replaceWith函数不起作用,因为include显然被some.php文件中带有空格和换行符的表单所取代。我试着在包括之前修剪,但没有效果。
如果我想用那种格式和换行符(而不是一行)将表单保存在some.php中,我该如何解决它?
您可以将include写入隐藏的文本区域并从中读取:
<textarea id="formhtml" style="display:none;"><?php include ('some.php'); ?></textarea>
然后更换h1:
$("h1").replaceWith($("#formhtml").html());