发布后如何在php代码中获取JS脚本

发布后如何在php代码中获取JS脚本,php,javascript,forms,Php,Javascript,Forms,我有一个发布到php页面的html表单。 在php页面上,我想显示一个带有格式选项的文本区域,这需要js脚本。当表单发布到php页面时,脚本不会被应用(我得到一个纯文本区域),但是如果直接转到.php页面,文本区域将显示格式选项(脚本成功运行)。 让我把代码放在更容易理解的地方 html格式: <!DOCTYPE html> <html> <head> <script src="http://js.nicedit.com/nicEdit-latest.j

我有一个发布到php页面的html表单。 在php页面上,我想显示一个带有格式选项的文本区域,这需要js脚本。当表单发布到php页面时,脚本不会被应用(我得到一个纯文本区域),但是如果直接转到.php页面,文本区域将显示格式选项(脚本成功运行)。 让我把代码放在更容易理解的地方

html格式:

<!DOCTYPE html>
<html>
<head>
<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);          </script>           
</head>
<body>
<form id="formOne" action="submitForm.php" method="post">
Enter your text below:</p>
<textarea name="userText" cols="70" rows="25"></textarea><br>
<p><input type="submit" value="Submit" /></p>
</div>

</form>
</body>

bkLib.ondomload(nicEditors.allTextAreas);
在下面输入您的文本:


php:


bkLib.ondomload(nicEditors.allTextAreas);

如您所见,我在head标记中包含了php中的脚本。 现在,如果我在html页面上单击submit,我将被引导到php页面,但是文本区域不会显示格式。 但是,如果直接转到php页面,textarea具有格式选项

所以在我看来,当我发布到php页面时,脚本没有被检测/读取

我试过不同的方法,比如

echo '<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"</script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>';

echo'POST不会像您提到的那样影响js脚本。尝试更改:

echo "<textarea name=userText2 cols=70 rows=25>".$current."</textarea>";
echo.“$current.”;


?>刚刚在我的服务器上尝试了这个示例,效果非常好。不知道是什么阻碍了你的服务器。以下是我的代码,仅供比较:

html:


这是一些简单的标记文本。
php:


bkLib.ondomload(nicEditors.allTextAreas);

我只是使用了您的代码,虽然我在表单中提交的值没有用于任何用途,但testing.html的内容实际上显示在所见即所得编辑工具栏的文本区域内。对我来说,当我提交表单时,testing.html的内容不会显示在所见即所得编辑工具栏的文本区域内。仅当我刷新页面或直接转到文件时。我也不认为这是一个浏览器问题……在文本区域之外,如果你从testing.html输出数据,它在那里吗?file_get_contents()也可以返回false,因此您需要运行类似$content==false的检查,以查看它是否成功读取该文件。是。从文件中读取数据没有问题您是否在某个服务器上运行此脚本,以便在运行脚本时查看submtiForm.php页面上的输出?嗯。可能是服务器问题,而不是代码问题。尽管此问题仅在单击“提交”时才持续存在。如果我刷新php页面或直接转到它,它工作正常
<?php
$current = file_get_contents($file);
?>
 <script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
<?php
  --rest of php code here--
?>
echo "<textarea name=userText2 cols=70 rows=25>".$current."</textarea>";
?><textarea name="userText2" cols="70" rows="25"><?php echo $current; ?></textarea><?php
<html>
<head>
<title></title>
</head>
<body>
<form method=post action=frm.php> 
<textarea rows=8 cols=60 name=userText>This is some simple <b>markup</b> text.</textarea>
<input type=submit name=ok value=ok>
</form>
</body>
</html>
<html>
<head>
<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
</head>
<body>
<?php   
$current = $_POST['userText'];
echo "<textarea name=userText2 cols=70 rows=25>$current</textarea>";    
?>
</body>
</html>