关于转账获取收账人
<!DOCTYPE html>
<html lang="zh-CN">
<?php
error_reporting(E_ALL &~ E_NOTICE);
// 代码是从上到下执行的,所以需要在页面开头开启session
session_start();
//使用pdo获取数据库中的用户信息
function showUser($name){
$dsn='mysql:host=localhost;dbname=imooc';
$pdo=new PDO($dsn,'root','root');
$pdo->exec('set names utf8');
// 需要接收传递的信息根据信息进行查询 如:
$sql="select * from student_management where name != '$name' ";
$stmt=$pdo->query($sql);
$data=$stmt->fetchAll(PDO::FETCH_ASSOC);
return $data;
}
$data=showUser($_SESSION['name']);
?>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>用户转账</title>
<link href="style/css/bootstrap.min.css" rel="stylesheet">
<link href="style/css/site.min.css" rel="stylesheet">
<style>
.container .row .col-lg-4 img{ display: block; margin-left: auto; margin-right: auto; }
.container .row .col-lg-4 h3,p{ text-align: center; }
.row .col-lg-4{text-align:center}
.row .col-lg-4 .button{ width: 360px;/* margin-left: 150px;*/ margin-bottom: 10px;}
</style>
</head>
<body>
<!--导航栏-->
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand hidden-sm" href="javascript:void(0)">慕课网</a>
</div>
<div class="navbar-header" style="display:none;" id="username">
<a class="navbar-brand hidden-sm" href="javascript:void(0)"><?php echo isset($_SESSION['name'])?$_SESSION['name']:'' ?>,欢迎您!</a>
</div>
</div>
</div>
<!--导航栏结束-->
<!--巨幕-->
<div class="jumbotron masthead">
<div class="container">
<h1>学生转账管理系统</h1>
<h2>实现学生转账功能</h2>
<p class="masthead-button-links">
<form class="form-inline" action="" method="get">
<div class="form-group">
<input type="text" class="form-control" id="exampleInputName2" placeholder="输入搜索内容" name="key" value="">
<button class="btn btn-default" type="submit">搜索</button>
<a href="register.php?action=register"><button type="button" class="btn btn-primary btn-default register" data-toggle="modal"> 注册 </button></a>
<a href="register.php?action=login"><button type="button" class="btn btn-primary btn-default login" data-toggle="modal"> 登录 </button></a>
<a href="register.php"><button type="button" class="btn btn-primary btn-default exit" data-toggle="modal"> 退出 </button></a>
</div>
</form>
</p>
</div>
</div>
<!--巨幕结束-->
<!-- 模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<form class="form-inline" action="#" method="post" enctype="multipart/form-data">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">转账</h4>
</div>
<div class="modal-body">
<p>
收款人:
<select class="form-control" onchange="fuzhi(this.options[this.selected].text)">
<?php foreach ($data as $v){?>
<option value=""><?php echo $v['name']?></option>
<?php }?>
</select>
</p>
<br />
<p>转账金额:<input type="text" name="transMoney" class="form-control" id="exampleInputEmail1" placeholder="请输入数字"></p>
</div>
<div class="modal-footer">
<input type="hidden" id="select_content" name="select_content"/>
<button type="submit" class="btn btn-primary" name="submit" id="submit" onclick="show(this)">确认转账</button>
<button type="reset" class="btn btn-default">重置</button>
</div>
</div>
</form>
</div>
</div>
<!--模态框结束-->
<div class="container projects">
<div class="projects-header page-header">
<h2>用户展示</h2>
<p>将用户信息展示在页面中</p>
</div>
<!--信息展示-->
<div class="row">
<?php foreach ($data as $v){ ?>
<div class="col-lg-4">
<img class="img-circle" src="upload/12.jpg" alt="" width="140" height="140">
<h3><?php echo $v['name']; ?></h3>
<p> <?php echo $v['info']; ?> </p>
<div class="button">
<button type="button" class="btn btn-primary btn-default" data-toggle="modal" data-target="#myModal"> 转账 </button>
</div>
</div>
<?php };?>
</div>
</div>
<footer class="footer container">
<div class="row footer-bottom">
<ul class="list-inline text-center">
<h4><a href="http://class.imooc.com" target="_blank">class.imooc.com</a> | 慕课网</h4>
</ul>
</div>
</footer>
<script src="style/js/jquery.min.js"></script>
<script src="style/js/bootstrap.min.js"></script>
<script>
function fuzhi(a){
document.getElementById("select_content").value=a;//赋值,咚咚
}
console.log(document.getElementById("select_content").value)
</script>
</body>
</html>
<?php
if($_SESSION['name']){
echo '<script>
document.getElementById("username").style.display="block";
document.getElementsByClassName("register")[0].style.display="none";
document.getElementsByClassName("login")[0].style.display="none";
//document.getElementsByClassName("exit")[0].style.display="block";
</script>';
}else{
echo '<script>
document.getElementById("username").style.display="none";
document.getElementsByClassName("register")[0].style.display="block";
document.getElementsByClassName("login")[0].style.display="block";
document.getElementsByClassName("exit")[0].style.display="none";
</script>';
}
?>
这个代码好像获取不了收账人的名字
正在回答 回答被采纳积分+1
同学你好,1. modal, show.bs.modal是bootstrap框架中自带的方法,同学可去查看bootstrap文档。
2. event是参数。relatedTarget.context是前端框架jquery中属性返回与事件的目标节点相关的节点。使用是必须需要绑定参数的哦(event 参数来自事件绑定函数)!
3. dataset.user是前端框架jquery中用来获取data-user值的。如:data-toggle="modal",使用dataset.toggle就可以获取到modal。
4. each是前端框架jquery中的循环语句。语法:$(document).each(function(选择器的 index 位置, 当前的元素(也可使用 "this" 选择器)))
// 如:循环得到每个li标签中的值 <html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("li").each(function(){ alert($(this).text()) }); }); }); </script> </head> <body> <button>输出每个列表项的值</button> <ul> <li>Coffee</li> <li>Milk</li> <li>Soda</li> </ul> </body> </html>
祝学习愉快!
<script type="text/javascript">
$("#exampleModal").modal("hide");
$('#myModal').on('show.bs.modal', function (event) {
// relatedTarget 事件属性返回与事件的目标节点相关的节点。
var a = $(event.relatedTarget)
var userName = a.context.dataset.user;
var modal = $(this);
//获取select option value值
$("#transfer-person").each(function(){
$('#transfer-person').val(userName);
});
});
</script>
完全看不懂这里面的内容,老师可以解释下吗
还有modal, show.bs.modal , event relatedTarget , a.content.dataset.user ,each这些是什么内容,在哪里可以看到相关文档,他们的用法是什么
同学你好,使用js实现下拉框默认值。首先转账按钮上添加data-user。代码如下:
<button type="button" class="btn btn-primary btn-default" data-toggle="modal" data-user="<?php echo $v['name'];?>" data-target="#myModal"> 转账 </button>
然后在收款人的select标签上添加id属性值。如下:
收款人: <select class="form-control" id='transfer-person' name="payee" > <?php foreach ($data as $v){?> <option value="<?php echo $v['name']?>"><?php echo $v['name']?></option> <?php }?> </select>
最后使用js实现效果。代码如下:
<script type="text/javascript"> $("#exampleModal").modal("hide"); $('#myModal').on('show.bs.modal', function (event) { // relatedTarget 事件属性返回与事件的目标节点相关的节点。 var a = $(event.relatedTarget) var userName = a.context.dataset.user; var modal = $(this); //获取select option value值 $("#transfer-person").each(function(){ $('#transfer-person').val(userName); }); }); </script>
祝学习愉快!
<form class="form-inline" action="transfer.class.php" method="post" enctype="multipart/form-data">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">转账</h4>
</div>
<div class="modal-body">
<p>
收款人:
<select class="form-control" name="payee" <!--onchange="fuzhi(this.options[this.selected].text)-->">
<?php foreach ($data as $v){?>
<option value=""><?php echo $v['name']?></option>
<?php }?>
</select>
</p>
<br />
<p>转账金额:<input type="text" name="transMoney" class="form-control" id="exampleInputEmail1" placeholder="请输入数字"></p>
</div>
<div class="modal-footer">
<!--<input type="hidden" id="select_content" name="select_content"/>-->
<button type="submit" class="btn btn-primary" name="submit" id="submit" onclick="show(this)">确认转账</button>
<button type="reset" class="btn btn-default">重置</button>
</div>
</div>
</form>
我之前就是这样也取不出来内容
<?php
header('Content-type:text/html;charset=utf-8');
echo $_POST['payee'];
echo $transMoney = $_POST['transMoney'];
还有在未登录状态下,我不知道应该怎么设置
<a href="register.php?action=register"><button type="button" class="btn btn-primary btn-default register" data-toggle="modal"> 注册 </button></a>
<a href="register.php?action=login"><button type="button" class="btn btn-primary btn-default login" data-toggle="modal"> 登录 </button></a>
这两个的样式使他们与搜索框在一条线上
- 参与学习 人
- 提交作业 225 份
- 解答问题 3372 个
掌握用PHP开发互联网网站的必备功能,掌握当下主流的Linux系统开发,并熟练使用热门框架ThinkPhp开发电商团购项目,是通向PHP工程师必经之路。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星