文章詳情頁
layui Ajax請求給下拉框賦值的實例
瀏覽:354日期:2022-06-11 14:03:37
如下所示:
<!DOCTYPE html> <html> <head> <title>排課設置</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <meta name="renderer" content="webkit"> <link rel="stylesheet" href="/vendor/layui/css/layui.css" rel="external nofollow" media="all"> </head> <body> <div lay-filter="boardFilter"> <hr> <div> <div> <label>查詢內容</label> <div> <input name="schName" placeholder="請輸入學校名稱" id="schName" autocomplete="off"> </div> </div> <div> <label>學期</label> <div> <select name="termId" id="termId"> </select> </div> </div> <div> <label>列表狀態</label> <div> <select name="msgType" id="msgType"> <option value="">全部狀態</option> <option value="1">申請中</option> <option value="2">確認申請</option> <option value="3">已經發布</option> <option value="0">已撤銷</option> </select> </div> </div> <div> <button lay-submit="" lay-filter="getSearch" id="getSearch" name="getSearch"><i></i> 查詢</button> </div> </div> </div> <table id="infoTable" lay-filter="filterTable"></table> <script type="text/javascript" src="/vendor/jquery/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="/vendor/layui/layui.js"></script> <script type="text/html" id="action"> <a lay-event="view">查看</a> {{# if(d.status===2){ }} <a lay-event="send">推送</a> {{# } }} {{# if(d.status===3){ }} <a href="{{d.url}}" class="layui-btn layui-btn-xs">下載排課表</a> {{# } }} </script> <script type="text/html" id="courseArrangeFlag"> {{# if(d.courseArrangeFlag===0){ }} <h>行政班排課</h> {{# } else { }} <h>走班排課</h> {{# } }} </script> <script type="text/html" id="status"> {{# if(d.status===0){ }} <h>撤消申請</h> {{# } else if(d.status===1){ }} <h>申請中</h> {{# } else if(d.status===2){ }} <h>排課中</h> {{# } else if(d.status===3){ }} <h>已經推送</h> {{# } else if(d.status===4){ }} <h>已發布課程表</h> {{# } }} </script> <script> layui.use(["table","layer"], function() { var table = layui.table ,form = layui.form; var $ = layui.jquery, layer = layui.layer; var tableIns = table.render({ elem: "#infoTable" ,url: "/web/courseArrange/list" ,id: "idTable" ,page: true ,limits: [10,20,50,100] ,limit: 10 //默認采用10 ,cols: [[ //標題欄 {checkbox: true, fixed: true} ,{field: "courseArrangeId", title: "序號", fixed: true} ,{field: "schName", title: "學校名稱"} ,{field: "courseArrangeFlag", title: "排課類型", templet: "#courseArrangeFlag"} ,{field: "termName", title: "學期"} ,{field: "recordTime", title: "申請時間"} ,{field: "status", title: "狀態", templet: "#status"} ,{field: "action", title: "操作", templet: "#action"} ]] }); //監聽管理操作 form.on("switch(schControlInput)", function(obj){ var normalValue if(obj.elem.checked){ normalValue = "0"; }else{ normalValue = "1"; } $.ajax({ url:"/school/editIsNormalSchool", type:"POST", dataType:"json", data:{"schId":this.value, "statusValue":normalValue}, success:function(res){ location.reload(); }, }); }); // 監聽Table工具條 table.on("tool(filterTable)", function(obj) { var data = obj.data; if (obj.event === "view") { location.href="courseArrangeView.html?id=" rel="external nofollow" +data.courseArrangeId+"&schId="+data.schId+"&areaId="+data.areaId; }else if (obj.event === "send") { layer.open({ type: 2, title: "導入并推送", maxmin: true, shadeClose: false, //點擊遮罩關閉層 area : ["700px" , "600px"], content: "/page/business/course/courseArrangeUpload.html?schId="+data.schId+"&areaId="+data.areaId+"&termId="+data.termId+"&courseArrangeFlag="+data.courseArrangeFlag+"&phone="+data.phone ,btn: "關閉" ,btnAlign: "c" //按鈕居中 ,shade: 0 //不顯示遮罩 ,yes: function(){ layer.closeAll(); } ,end: function () { location.reload(); } }); } }); form.on("submit(getSearch)", function(data){ table.reload("idTable", { where: data.field }); }); $(document).ready(function () { $("select[name=termNm]").empty(); $.ajax({ async: false, type: "POST", url: "/web/courseArrange/termList", dataType: "json", data: {}, success: function (res) { var opt = "<option value="" selected = \"selected\">全部</option>"; $("select[name=termId]").append(opt); for(var i=0; i<res.data.length; i++){ var option="<option value=\""+res.data[i].termId+"\""; option += ">"+res.data[i].termName+"</option>"; //動態添加數據 $("select[name=termId]").append(option); } layui.form.render("select","boardFilter"); } }); }); }); </script> </body> </html>
以上這篇layui Ajax請求給下拉框賦值的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持。
標簽:
Ajax
相關文章:
排行榜
