[英]Why aren't <script> tags not working on this PHP page?
When I try to enter当我尝试输入时
<script type="text/javascript" >
alert("hello");
</script>
in the comment box on my PHP page I do not get an alert box.在我的 PHP 页面的评论框中,我没有收到警告框。 I see the script in my text file, not on the webpage.我在我的文本文件中看到脚本,而不是在网页上。 For some reason the <script>
isn't executing.出于某种原因, <script>
没有执行。 I have active scripting and javascript enabled on all my browsers.我在所有浏览器上都启用了活动脚本和 javascript。
My PHP code:
<?php //CFPcomments.php
include_once 'CFPheader.php';
if (isset($_POST['content']))
{
$fp = fopen('comments.txt', 'a');
fwrite($fp, $_POST['content'] . "<br />");
fclose($fp);
}
echo nl2br(file_get_contents('comments.txt'));
echo <<<_END
<h3>Post comment</h3>
<form action='CFPcomments.php' method='post'>
<textarea name='content' rows ='3' cols='100'></textarea>
<br/>
<input type='submit' value='Post' />
</form>
_END;
?>
Strange.奇怪的。 I got it to work, not sure why.我让它工作,不知道为什么。
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
alert("hello");
</script>
</head>
<body>
</body>
</html>
When I type this in it seems to work当我输入它似乎工作
Anyone have any idea why????任何人都知道为什么???? Very confused.非常困惑。
your nl2br()
is most likely translating您的nl2br()
很可能正在翻译
<script type="text/javascript" >
alert("hello");
</script>
to到
<script type="text/javascript" ><br/>
alert("hello");<br/>
</script><br/>
and breaking the JavaScript code.并破坏 JavaScript 代码。
I assigned a variable to the content, then displayed the variable in the PHP code.我为内容分配了一个变量,然后在 PHP 代码中显示了该变量。 Now it works.现在它起作用了。
<?php //CFPcomments.php
include_once 'CFPheader.php';
setcookie("username", $GLOBALS['user'], time()+3600);
setcookie("password", $GLOBALS['pass'], time()+3600);
if (isset($_POST['content']))
{
$fp = fopen('comments.txt', 'a');
fwrite($fp, $_POST['content'] . "<br />");
fclose($fp);
}
$comment = file_get_contents('comments.txt');
echo <<<_END
<h3>Post comment</h3>
'$comment'
<form action='CFPcomments.php' method='post'>
<textarea name='content' rows ='3' cols='100'></textarea>
<br/>
<input type='submit' value='Post' />
</form>
_END;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.