我的function error()
不能从php代码调用。 好心帮我解决这个问题。当在php代码外部调用时,fucntion可以正常工作。但是当调用insisde php代码时没有显示输出。JavaScript函数不能在php代码中调用
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" href="css/design.css">
<script type="text/JavaScript">
function error(){
document.getElementById("wrong-attempt").innerHTML="Wrong Username Or Password";
}
</script>
<?php
if(isset($_POST['submit'])){
echo '<script> error(); </script>';
}
?>
</head>
<body background="pics/background.jpg">
<div class="wrapper">
<center>
<div class="form-wrapper">
<form action="index.php" method="POST">
<div>
</div>
<h1>User Login</h1>
<div>
<img src="pics/login.png" width="100" height="100"/>
</div>
<div>
<input name="ID" placeholder=" Username" type="text" required="true"/></br>
<input name="pass" placeholder=" Password" type="password" required="true"></br>
<input type="image" src="pics/loginb.png" name="submit" value="Login" width="100"/>
</div>
</form>
<div id="wrong-attempt">
</div>
</div>
<center/>
</div>
</body>'
</html>
用'<?php if(!empty($ _ POST)){echo'
您的函数被调用得太快,要么将脚本放在底部,要么将其包装在domready处理程序中。 – fedeghe
如果您曾经计划使用脚本提交,也从来不会调用任何形式的'name =“submit”' – mplungjan