【发布时间】:2015-07-10 08:28:34
【问题描述】:
我有一个简单的登录注册表单,当用户输入错误的电子邮件时,他们会显示“正在使用电子邮件”的文本,但是此文本是通过 php echo 完成的,因此我无法编辑其样式和定位.我能想到的唯一方法是使用javascript而不是php echo,这样我就可以将消息输出到另一个已经设置样式的div。我想将消息输出到 div id #log 中。我试过 $('#log').innerHTML = 'Your text.';但是,这是行不通的。
这是我的代码:
<?php
session_start();
include_once 'authentication/dbconnect.php';
if(isset($_SESSION['user'])!="")
{
header("Location: account.php");
}
if(isset($_POST['btn-login']))
{
$email = mysql_real_escape_string($_POST['email']);
$upass = mysql_real_escape_string($_POST['pass']);
$res=mysql_query("SELECT * FROM users WHERE email='$email'");
$row=mysql_fetch_array($res);
if($row['password']==md5($upass))
{
$_SESSION['user'] = $row['user_id'];
header("Location: account.php");
}
else
{
?>
<script>$('#log').innerHTML = 'Your text.';</script>
<?php
}
}
?>
<!DOCTYPE html>
<html>
<HEAD>
<title>Website | Loign</title>
<?php include "includes/page_sources.php"; ?>
</HEAD>
<body>
<?php include "includes/navigation.php"; ?>
<div id="wrapper">
<div id="log"></div>
<div id="login-form">
<form method="post">
<input type="text" name="email" placeholder="Your Email" required />
<input type="password" name="pass" placeholder="Your Password" required />
<button type="submit" name="btn-login">Log In</button>
<a href="register.php">Sign Up</a>
</form>
</div>
</div>
<?php include "includes/footer.php"; ?>
</body>
</html>
【问题讨论】:
-
在 jquery 中它是 .html("...") 而不是 innerhtml。试试这个:)
标签: javascript php jquery html