Layui提供的功能如下(预览)
可自行查看:layui官网此模块的链接
着急看双击选中 直接看标黄色部分
假设这是个弹窗里的表格和数据点击圆圈,圆圈变绿则为选中,选中后点击上方查看数据按钮(实际中是确认按钮,实际中点击确认按钮后会关闭弹窗并把json串带到原本页面中)
Layui提供的代码如下(查看代码)
<body> <!-- 表格空架子 --> <table class="layui-hide" id="test" lay-filter="test"></table> <!-- 确认(查看数据按钮) --> <script type="text/html" id="toolbarDemo"> <div class="layui-btn-container"> <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button> </div> </script> <script src="/UploadFiles/2021-04-02/layui.js">实际需求实例
- 点击 【选择】 按钮,出现弹框
- 弹框里有数据表格
- 点击圆圈为选中当前条数据
- 点击弹框中【确认】把选中条数据带到主页面
实际代码实例
主页面代码(底,都为自动带出的输入框)
静态部分
<div> <div> <span>客户姓名:</span> <form:input path="customerName" readonly="true"/> <span onclick="onclick()" title="选择"> <input id="selectCustomer" class="btn" type="button" value="选择" /></span> </div> <div> <span>客户性别:</span> <form:input path="customerSex" readonly="true"/> </div> <div> <span>客户年龄:</span> <form:input path="customerYears" readonly="true"/> </div> </div>
【选择】按钮的弹窗事件
function onclick(){
var width = window.screen.availWidth*0.8;
var height = window.screen.availHeight*0.65;
var iTop=(window.screen.availHeight-30-height)/2;
var iLeft=(window.screen.availWidth-30-width)/2;
var url="${xxx}/vvvv/rrrrr/getCustomerList"; //后端代码就不介绍了
window.open(url,'客户信息','height='+height+',width='+width+',top='+iTop+',left='+iLeft+',
toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no')
}
弹窗页面代码
弹窗页面中–静态部分
<table id="contentTable" class="layui-table">
<thead>
<tr>
<th></th>
<th>客户姓名</th>
<th>客户性别</th>
<th>客户年龄</th>
<th>...</th>
</tr>
</thead>
<tbody>
<c:forEach items="${page.list}" var="customerMain">
<tr>
<td align="center"><input name="customerId" type="radio" value="${customerMain.id}"></td>
<td>${customerMain.customerName}</td>
<td>${customerMain.customerSex}</td>
<td>${customerMain.customerYears}</td>
<td class="hide" >${customerMain.....}</td>
</tr>
</c:forEach>
</tbody>
</table>
弹框页面上-- == 单击单选圆圈的事件+双击行选中 ==
$(document).ready(function() {
//双击行 即可执行函数(行数据被选中:radio为checked)
$("table tbody tr").dblclick(function(i) {
$(this).find("input[type='radio']").prop("checked", true)
});
//圆圈改变状态即可执行函数
$("#contentTable tbody tr input").change(function () {
var ischecked = $(this).prop("checked");
var index=$(this).parent().parent().index()
var tr=$("#contentTable tbody tr")
if(ischecked){
for(var i=0;i<tr.length;i++){
if(i!=index){
$("#contentTable tbody tr:eq("+i+") input").prop("checked",!ischecked);
}
}
}
})
});
弹框页面上–选择好数据后带回主页面的函数
<script>
//给弹框中【确认】按钮绑定事件
function toSubmit(){
//此方法在下方
var data=getRowData();
if(data==null){
layer.alert("请先选择一位客户")
return ;
}
window.opener.getCustomerData(data);//调用主页面上的方法,给主页面赋值,最下方有具体方法过程
window.close();//关闭弹窗
}
//给弹框中【返回】按钮绑定事件
function closed(){
window.close();
}
//获取行对象
function getRowData(){
var row = null;
//锁定行(循环遍历找到被选中的行)
$("table tbody tr").each(function(){
var radio = $(this).find("td").eq(0).find("input[type='radio']:checked").val();
if(radio){
row = $(this) ;
}
});
//如果此行有数据则拼接
if(row){
var customerId = row.find("td").eq(0).find("input[type='radio']:checked").val();
var customerName = row.find("td").eq(1).text();
var customerSex = row.find("td").eq(2).text();
var customerYears = row.find("td").eq(3).text();
//拼接模板 $.trim() jQuery.trim()函数用于去除字符串两端的空白字符。该函数可以去除字符串开始和末尾两端的空白字符(直到遇到第一个非空白字符串为止)。它会清除包括换行符、空格、制表符等常见的空白字符。
var data = "[{\"customerId\":\""+$.trim(customerId)
+"\",\"customerName\":\""+$.trim(customerName)
+"\",\"customerSex\":\""+$.trim(customerSex)
+"\",\"customerYears\":\""+$.trim(customerYears)
+"\"}]";
}
return data ;
}
</script>
调用主页面上的给主页面赋值的方法
<script>
function getCustomerData(data){
var json = JSON.parse(data);
$("#customerId").val(json[0].customerId);
$("#customerName").val(json[0].customerName);
$("#customerSex").val(json[0].customerSex);
$("#customerYears").val(json[0].customerYears);
....
}
</script>
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“Layui弹框中数据表格中可双击选择一条数据的实现”评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新动态
2025年10月30日
2025年10月30日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]

