thymeleaf+bootstrap,onclick实现传订单id到模态框中

本文介绍了如何在SpringBoot项目中,利用Thymeleaf模板引擎和Bootstrap模态框,实现在点击按钮时将订单ID传送到模态框展示的详细步骤和代码示例。


下面是一个评价订单的功能代码


<a id="myModal" data-toggle="modal" data-target="#exampleModal" th:onclick="'javascript:Values('+${item.id}+')'">评价服务</a>

模态框代码

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">评价</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
         
<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('123456789')"/> <th:block th:include="include :: datetimepicker-css"/> <!-- <th:block th:include="include :: datetimepicker-css"/>--> <th:block th:include="include :: bootstrap-fileinput-css"/> </head> <style> </style> <body> <form id="form-add" class="form-horizontal"> <div class="row"> <div class="col-sm-12"> <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button> <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i> </button> <div class="col-sm-12 select-table table-striped"> <table id="bootstrap-table"></table> </div> </div> </div> <div class="row"> <div class="col-sm-offset-5 col-sm-10"> <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存 </button>  <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button> </div> </div> </form> <!--style="opacity: 0;position: absolute;z-index: -1;"--> <!--<div>--> <!-- <div class='file-loading'>--> <!-- <input class='form-control file-upload' name='file' type='file' id="filex">--> <!-- </div>--> <!--</div>--> <th:block th:include="include :: footer"/> <th:block th:include="include :: echarts-js"/> <th:block th:include="include :: datetimepicker-js"/> <th:block th:include="include :: bootstrap-fileinput-js"/> <script th:inline="javascript"> $(function () { // 初始化数据, 可以由后台过来 var data = [ { id: "100", name: "商品名称", weight: "100", price: "12.5", date: "2021-02-01", upload: "", type: "1", }, { id: "101", name: "商品名称2", weight: "50", price: "10.8", date: "2021-02-01", upload: "", type: "0", }]; var options = { data: data, pagination: false, showSearch: false, showRefresh: false, showToggle: false, showColumns: false, sidePagination: "client", columns: [{ checkbox: true }, { field: 'index', align: 'center', title: "序号", formatter: function (value, row, index) { var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index)); var columnId = $.common.sprintf("<input type='hidden' name='goods[%s].id' value='%s'>", index, row.id); return columnIndex + $.table.serialNumber(index) + columnId; // return $.table.serialNumber(index) + columnId; } }, { field: 'name', align: 'center', title: '商品名称', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].name' value='%s' >", index, value); return html; } }, { field: 'weight', align: 'center', title: '商品重量', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].weight' value='%s' >", index, value); return html; } }, { field: 'date', align: 'center', title: '商品日期', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].date' value='%s' >", index, value); return html; } }, { field: 'price', align: 'center', title: '商品价格', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].price' value='%s' >", index, value); return html; } }, { field: 'type', align: 'center', title: '商品种类', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].type' value='%s' >", index, value); return html; } }, { field: 'upload', align: 'center', title: '上', formatter: function (value, row, index) { // var upload = $.common.sprintf("<input class='file-upload' id='goods[%s].upload' name='file' type='file'>", index); var html = $.common.sprintf("<input type='hidden' name='goods[%s].upload' value='%s' >", index, row.upload); var button = $.common.sprintf("<input type='button' onclick='uploaddata(%s)' value='上' class='btn btn-primary'></input>", index); return html + button; } }, { title: '操作', align: 'center', formatter: function (value, row, index) { var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index); return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>'; } }] }; $.table.init(options); }); function addRow() { var count = $("#" + table.options.id).bootstrapTable('getData').length; var row = { index: $.table.serialNumber(count), name: "", weight: "", price: "", date: "", type: "", } sub.addRow(row); }; /* 主子表-提交 */ function submitHandler(index, layero) { var data = $("#form-add").serializeArray(); alert(JSON.stringify(data)) $.operate.saveModal("", data); } $(".file-upload").fileinput({ uploadUrl: ctx + 'common/upload', maxFileCount: 1, autoReplace: true, showPreview: false }).on('fileuploaded', function (event, data, previewId, index) { $("input[name='" + event.currentTarget.id + "']").val(data.response.url) }).on('fileremoved', function (event, id, index) { $("input[name='" + event.currentTarget.id + "']").val('') }) function uploaddata(data) { var url = ctx + "system/COMBINE" + "/one7"; // $.modal.open('onetest', url) $.modal.openOptions({ title: '上文件', url: url, btn: 0 }) // alert(data); const namex = "goods" + "[" + data + "]" + ".upload" // alert(namex); $("input[name='" + namex + "']").val("1") } </script> </body> </html> 这是我的一个页面,我点击打开,一个ruoyi的模态框,<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('123456789')"/> <th:block th:include="include :: datetimepicker-css"/> <!-- <th:block th:include="include :: datetimepicker-css"/>--> <th:block th:include="include :: bootstrap-fileinput-css"/> </head> <style> </style> <body> <div> <div> <input type="text" name="filex" id="inputfile"> <div class='file-loading'> <input class='form-control file-upload' name='file' type='file' id="filex"> </div> </div> <div> <button onclick="chuli()">确定</button> </div> </div> <th:block th:include="include :: footer"/> <th:block th:include="include :: echarts-js"/> <th:block th:include="include :: datetimepicker-js"/> <th:block th:include="include :: bootstrap-fileinput-js"/> <script th:inline="javascript"> $(".file-upload").fileinput({ uploadUrl: ctx + 'common/upload', maxFileCount: 1, autoReplace: true, showPreview: false }).on('fileuploaded', function (event, data, previewId, index) { $("input[name='" + event.currentTarget.id + "']").val(data.response.url) }).on('fileremoved', function (event, id, index) { $("input[name='" + event.currentTarget.id + "']").val('') }) function chuli() { const x = document.getElementById("inputfile"); alert(x.value); } </script> </body> </html> 然后,我使用fileinput上文件会吧url存入input框中,最后我点击确定,把值回去,我该怎么做
09-09
#@setReqNoAllLog() #@setReqType("text/html") #@setParam(["zdlx"]) #bodyget_rs() #[[ <!DOCTYPE html> <html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="keywords" content=""> <meta name="description" content=""> <title>模板配置</title> <link rel="shortcut icon" href="favicon.ico"> <link href="/jf_view/ruoyi/css/bootstrap.min.css" rel="stylesheet"/> <link href="/jf_view/ruoyi/css/font-awesome.min.css" rel="stylesheet"/> <!-- bootstrap-table 表格插件样式 --> <link href="/jf_view/ruoyi/ajax/libs/bootstrap-table/bootstrap-table.min.css?v=20210202" rel="stylesheet"/> <link href="/jf_view/ruoyi/ajax/libs/bootstrap-table/bootstrap-table-pagejump.css?v=20210202" rel="stylesheet"/> <link href="/jf_view/ruoyi/css/animate.css" rel="stylesheet"/> <link href="/jf_view/ruoyi/css/style.css?v=20200903" rel="stylesheet"/> <link href="/jf_view/ruoyi/ruoyi/css/ry-ui.css?v=4.6.0" rel="stylesheet"/> <style> .status-show{ cursor:pointer; } </style> </head> <body class="gray-bg"> <div class="container-div"> <div class="row"> <div class="col-sm-12 search-collapse"> <form id="type-form"> <div class="select-list"> <ul> <li> <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i> 刷新</a> </li> </ul> </div> </form> </div> <div class="btn-group-sm" id="toolbar" role="group"> </div> <div class="col-sm-12 select-table table-striped"> <table id="bootstrap-table"></table> </div> </div> </div> <script> var ctx = "\/jf_view\/"; var lockscreen = null; if(lockscreen){window.top.location=ctx+"lockscreen";} </script> <a id="scroll-up" href="#" class="btn btn-sm display"><i class="fa fa-angle-double-up"></i></a> <script src="/jf_view/ruoyi/js/jquery.min.js"></script> <script src="/jf_view/ruoyi/js/bootstrap.min.js"></script> <!-- bootstrap-table 表格插件 --> <script src="/jf_view/ruoyi/ajax/libs/bootstrap-table/bootstrap-table.min.js?v=20210202"></script> <script src="/jf_view/ruoyi/ajax/libs/bootstrap-table/bootstrap-table-pagejump.js?v=20210202"></script> <script src="/jf_view/ruoyi/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js?v=20210202"></script> <script src="/jf_view/ruoyi/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js?v=20210202"></script> <!-- jquery-validate 表单验证插件 --> <script src="/jf_view/ruoyi/ajax/libs/validate/jquery.validate.min.js"></script> <script src="/jf_view/ruoyi/ajax/libs/validate/messages_zh.min.js"></script> <script src="/jf_view/ruoyi/ajax/libs/validate/jquery.validate.extend.js"></script> <!-- jquery-validate 表单树插件 --> <script src="/jf_view/ruoyi/ajax/libs/bootstrap-treetable/bootstrap-treetable.js"></script> <!-- 遮罩层 --> <script src="/jf_view/ruoyi/ajax/libs/blockUI/jquery.blockUI.js"></script> <script src="/jf_view/ruoyi/ajax/libs/iCheck/icheck.min.js"></script> <script src="/jf_view/ruoyi/ajax/libs/layer/layer.min.js"></script> <script src="/jf_view/ruoyi/ajax/libs/layui/layui.js"></script> <script src="/jf_view/ruoyi/ruoyi/js/common.js?v=4.6.0"></script> <script src="/jf_view/ruoyi/ruoyi/js/ry-ui.js?v=4.6.0"></script> <script> var editFlag = ""; var listFlag = ""; var removeFlag = ""; var datas = [{"searchValue":null,"createBy":"admin","createTime":"2021-12-17 10:32:46","updateBy":null,"updateTime":null,"remark":"\u6B63\u5E38\u72B6\u6001","params":{},"dictCode":6,"dictSort":1,"dictLabel":"\u6B63\u5E38","dictValue":"0","dictType":"sys_normal_disable","cssClass":"","listClass":"primary","isDefault":"Y","status":"0","default":true},{"searchValue":null,"createBy":"admin","createTime":"2021-12-17 10:32:46","updateBy":null,"updateTime":null,"remark":"\u505C\u7528\u72B6\u6001","params":{},"dictCode":7,"dictSort":2,"dictLabel":"\u505C\u7528","dictValue":"1","dictType":"sys_normal_disable","cssClass":"","listClass":"danger","isDefault":"N","status":"0","default":false}]; var prefix = ctx + "api/his_pdjh/api_ui/interface"; $(function() { var options = { url: prefix + "/sign_cf_data", createUrl: prefix + "/add", updateUrl: prefix + "/sign_cf_edit?id={id}", removeUrl: prefix + "/del?id={id}", exportUrl: prefix + "/export", sortName: "ROOMID", sortOrder: "asc", modalName: "队列签到成功配置 ", columns: [{ checkbox: true }, { field: 'ROOMID', title: '队列', sortable: true, formatter: function(value, row, index) { return $.table.tooltip(value); } }, { field: 'ROOMNAME', title: '队列名称', sortable: true, formatter: function(value, row, index) { return $.table.tooltip(value); } }, { title: '操作', align: 'center', formatter: function(value, row, index) { var actions = []; actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.ROOMID + '\')"><i class="fa fa-edit"></i>编辑</a> '); //actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.ZJPIP+ '\')"><i class="fa fa-remove"></i>删除</a>'); return actions.join(''); } }] }; $.table.init(options); }); /*字典列表-详细*/ function detail(dictId) { var url = prefix + '/detail/index?id=' + dictId; $.modal.openTab("字典数据", url); } /** 刷新字典缓存 */ function refreshCache() { $.operate.post(prefix + "/del_cache",{},function(rs){ $.table.refresh(); }) } /* 定时任务状态显示 */ function statusTools(row) { if (row.DEL_FLAG == "1") { return '<i class=\"fa fa-toggle-off status-show text-info fa-2x\" onclick="enable(\'' + row.ZJPIP + '\')"></i> '; } else { return '<i class=\"fa fa-toggle-on status-show text-info fa-2x\" onclick="disable(\'' + row.ZJPIP + '\')"></i> '; } } /* 定时任务管理-停用 */ function disable(roleId) { $.modal.confirm("确认要停用吗?", function() { $.operate.post(prefix + "/update_status", { "ID": roleId, "STATUS": "1" }); }) } /* 定时任务管理启用 */ function enable(roleId) { $.modal.confirm("确认要启用吗?", function() { $.operate.post(prefix + "/update_status", { "ID": roleId, "STATUS": "0" }); }) } </script> </body> </html> ]]# #end #@throwMsg(rs.trim()) 这页面中,想让roomname与id一起如何坐
最新发布
11-25
<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('123456789')"/> <th:block th:include="include :: datetimepicker-css"/> <!-- <th:block th:include="include :: datetimepicker-css"/>--> <th:block th:include="include :: bootstrap-fileinput-css"/> </head> <style> </style> <body> <form id="form-add" class="form-horizontal"> <div class="row"> <div class="col-sm-12"> <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button> <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i> </button> <div class="col-sm-12 select-table table-striped"> <table id="bootstrap-table"></table> </div> </div> </div> <div class="row"> <div class="col-sm-offset-5 col-sm-10"> <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存 </button>  <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button> </div> </div> </form> <!--style="opacity: 0;position: absolute;z-index: -1;"--> <!--<div>--> <!-- <div class='file-loading'>--> <!-- <input class='form-control file-upload' name='file' type='file' id="filex">--> <!-- </div>--> <!--</div>--> <th:block th:include=“include :: footer”/> <th:block th:include=“include :: echarts-js”/> <th:block th:include=“include :: datetimepicker-js”/> <th:block th:include=“include :: bootstrap-fileinput-js”/> <script th:inline="javascript"> $(function () { // 初始化数据, 可以由后台过来 var data = [ { id: "100", name: "商品名称", weight: "100", price: "12.5", date: "2021-02-01", upload: "", type: "1", }, { id: "101", name: "商品名称2", weight: "50", price: "10.8", date: "2021-02-01", upload: "", type: "0", }]; var options = { data: data, pagination: false, showSearch: false, showRefresh: false, showToggle: false, showColumns: false, sidePagination: "client", columns: [{ checkbox: true }, { field: 'index', align: 'center', title: "序号", formatter: function (value, row, index) { var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index)); var columnId = $.common.sprintf("<input type='hidden' name='goods[%s].id' value='%s'>", index, row.id); return columnIndex + $.table.serialNumber(index) + columnId; // return $.table.serialNumber(index) + columnId; } }, { field: 'name', align: 'center', title: '商品名称', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].name' value='%s' >", index, value); return html; } }, { field: 'weight', align: 'center', title: '商品重量', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].weight' value='%s' >", index, value); return html; } }, { field: 'date', align: 'center', title: '商品日期', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].date' value='%s' >", index, value); return html; } }, { field: 'price', align: 'center', title: '商品价格', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].price' value='%s' >", index, value); return html; } }, { field: 'type', align: 'center', title: '商品种类', formatter: function (value, row, index) { var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].type' value='%s' >", index, value); return html; } }, { field: 'upload', align: 'center', title: '上', formatter: function (value, row, index) { // var upload = $.common.sprintf("<input class='file-upload' id='goods[%s].upload' name='file' type='file'>", index); var html = $.common.sprintf("<input type='text' name='goods[%s].upload' value='%s' >", index, row.upload); var button = $.common.sprintf("<input type='button' onclick='uploaddata(%s)' value='上' class='btn btn-primary'></input>", index); return html + button; } }, { title: '操作', align: 'center', formatter: function (value, row, index) { var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index); return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>'; } }] }; $.table.init(options); }); function addRow() { var count = $("#" + table.options.id).bootstrapTable('getData').length; var row = { index: $.table.serialNumber(count), name: "", weight: "", price: "", date: "", type: "", } sub.addRow(row); }; /* 主子表-提交 */ function submitHandler(index, layero) { var data = $("#form-add").serializeArray(); alert(JSON.stringify(data)) $.operate.saveModal("", data); } $(".file-upload").fileinput({ uploadUrl: ctx + 'common/upload', maxFileCount: 1, autoReplace: true, showPreview: false }).on('fileuploaded', function (event, data, previewId, index) { $("input[name='" + event.currentTarget.id + "']").val(data.response.url) }).on('fileremoved', function (event, id, index) { $("input[name='" + event.currentTarget.id + "']").val('') }) // 在打开子页面前设置全局变量存储当前索引 let currentUploadIndex = null; function uploaddata(index) { currentUploadIndex = index; // 存储当前操作的行索引 var url = ctx + "system/COMBINE/one7"; $.modal.openOptions({ title: '上文件', url: url, btn: 0 }) } // 修改消息监听(确保在document ready前执行) window.addEventListener("message", function(event) { // 验证消息来源(提高安全性) // if (event.origin !== window.location.origin) return; console.log(event); if (event.data && event.data.type === "uploadComplete") { const url = event.data.value; const index = currentUploadIndex; // 使用全局存储的索引 console.log("收到上完成消息:", {url, index}); $("input[name='goods[" + index + "].upload']").val(url); } }, false); </script> </body> </html> <!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head> <th:block th:include="include :: header('123456789')"/> <th:block th:include="include :: datetimepicker-css"/> <!-- <th:block th:include="include :: datetimepicker-css"/>--> <th:block th:include="include :: bootstrap-fileinput-css"/> </head> <style> </style> <body> <div> <div> <input type="text" name="filex" id="inputfile"> <div class='file-loading'> <input class='form-control file-upload' name='file' type='file' id="filex"> </div> </div> <div> <button onclick="chuli()">确定</button> </div> </div> <th:block th:include="include :: footer"/> <th:block th:include="include :: echarts-js"/> <th:block th:include="include :: datetimepicker-js"/> <th:block th:include="include :: bootstrap-fileinput-js"/> <script th:inline="javascript"> $(".file-upload").fileinput({ uploadUrl: ctx + 'common/upload', maxFileCount: 1, autoReplace: true, showPreview: false }).on('fileuploaded', function (event, data, previewId, index) { $("input[name='" + event.currentTarget.id + "']").val(data.response.url) }).on('fileremoved', function (event, id, index) { $("input[name='" + event.currentTarget.id + "']").val('') }) function chuli() { const url = $("#inputfile").val(); // console.log(url); if (!url) { alert("请先上文件"); return; } $.modal.close(); } </script> </body> </html> 这是我的两个页面的代码,我使用的是ruoyi框架是使用bootstrap前端框架的版本 我现在需要点击按钮,跳转到使用ruoyi自带的openoptions打开的页面来上文件然后点击确定按钮把url回原页面,进行处理
09-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值