function msg ($msg) {
echo "<script type='text/javascript'>alert('$msg');</script>";
}
if (count($_POST)) {
msg('TEST!!!!!');
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My website</title>
<link rel="stylesheet" type="text/css" href="/assets/css/main.css" />
</head>
<body>
<div id="content">
<form action="/user/register" method="post">
<table cellspacing="2" cellpadding="0">
<tr>
<td>Username:</td>
<td><input name="username" maxlength="25" size="25" type="text" />
</td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="email" maxlength="255" size="25" type="text" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" maxlength="255" size="25" type="password" /></td>
</tr>
<tr>
<td>Confirm password:</td>
<td><input name="password2" maxlength="255" size="25" type="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Register" /></td>
</tr>
</table></div>
</body>
</html>
当我发贴时,当提示显示警告但在空白页上。当我按提交时,表格消失了。我该怎么办仍显示html?
消息弹出,但在空白页上。我希望它仍显示您的页面
最佳答案
首先,您需要将脚本放在标签中,而不是DOCTYPE上方。尝试这个
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My website</title>
<link rel="stylesheet" type="text/css" href="/assets/css/main.css" />
<?php
if (count($_POST)) {
msg('TEST!!!!!');
}
?>
</head>
在那之后,可能会有更多的问题。
关于javascript - 帮助JavaScript警报,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1214172/