【发布时间】:2016-08-26 08:13:05
【问题描述】:
我想获取一个函数的返回值并显示到一个特定的id。
在我的 Class.php 中,我有一个名为 login 的函数,用于验证密码是否正确/不正确
<?php
class Class
{
public function login()
{
if($_POST['password'] == Match) {
return 'Correct Password!';
} else {
return 'Incorrect password!';
}
}
}
在我的 index.php 中有这个 html。现在如何在我的 html 标记中获取我的登录函数的返回值,ID 为 check
<?php
require_once 'Class.php';
$class = new Class();
$class->login();
?>
<!DOCTYPE html>
<html>
<head>
<title>SOMETHING</title>
</head>
<body>
<form action="" method="POST">
<input type="text" name="username">
<input type="password" name="password">
<span id="check"></span> <!-- I want to put the returned value here -->
<input type="submit" value="Login">
</form>
</body>
</html>
【问题讨论】:
-
<span id="check"><?php echo $class->login();?></span> -
但是你真的应该做自己的功课