1. 程式人生 > >獲取標籤以及json字串拼接

獲取標籤以及json字串拼接

<div class="ibox float-e-margins">
    <div class="ibox-content">
        <div class="form-horizontal">
     <!--   <form id="form" action="/pressureseting/updatepressureseting" method="post">-->
       <form id="form">
            <div class="nax">
            <
table class="table table-bordered" id="dataTable1"> <tr> <th style="width: 100px;text-align: center"> 投注型別 </th> <th style="width: 80px;text-align: center"> 退水
</th> <th style="width: 80px;text-align: center"> 單注下限 </th> <th style="width: 80px;text-align: center"> 單註上限 </th> <
th style="width: 80px;text-align: center"> 單注限額 </th> </tr> @for(s in item){ @if(sLP.index <= 8){ <tr> <td id="1"> <input type="hidden" name="id" value="${s.id!}"/> ${s.waysPlaying.value!} </td> <td> <input class="active" name="dewater" value="${s.dewater!}" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" style="width: 60px;text-align: center">% </td> <td> <input class="active" name="singleFloor" value="${s.singleFloor!}" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" style="width: 60px;text-align: center"> </td> <td> <input class="active" name="singleUpper" value="${s.singleUpper!}" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" style="width: 60px;text-align: center"> </td> <td> <input class="active" name="singleQuota" value="${s.singleQuota!}" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" style="width: 60px;text-align: center"> </td> </tr> @} @} </table>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <table class="table table-bordered" id="dataTable2"> <tr> <th style="width: 100px;text-align: center"> 投注型別 </th> <th style="width: 80px;text-align: center"> 退水 </th> <th style="width: 80px;text-align: center"> 單注下限 </th> <th style="width: 80px;text-align: center"> 單註上限 </th> <th style="width: 80px;text-align: center"> 單注限額 </th> </tr> @for(s in item){ @if(sLP.index > 8){ <tr> <td> <input type="hidden" name="id" value="${s.id!}"/> ${s.waysPlaying.value!} </td> <td> <input class="active" name="dewater" value="${s.dewater!}" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" style="width: 60px;text-align: center">% </td> <td> <input class="active" name="singleFloor" value="${s.singleFloor!}" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" style="width: 60px;text-align: center"> </td> <td> <input class="active" name="singleUpper" value="${s.singleUpper!}" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" style="width: 60px;text-align: center"> </td> <td> <input class="active" name="singleQuota" value="${s.singleQuota!}" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" style="width: 60px;text-align: center"> </td> </tr> @} @} </table> </div> </form> </div> <div class="col-sm-10"> <#button btnCss="info" name="儲存" id="ensure" icon="fa-check" clickFun="PressureSetingInfoDlg.addSubmit()"/> </div> </div> <script type="text/javascript"> function submit() { $('.active').attr("style","width:60px;text-align: center;border-color:#f5f5f5"); var reg = /^[0-9]+([.]{1}[0-9]+){0,1}$/ ; // var zhenreg = /^[1-9]\d*$/; // 正整數表示式 var jsonStr="[" try { $('#dataTable1 tr').each(function (i) { if ($(this).children('td').length > 0) { jsonStr += "{" $(this).children('td').each(function (j) { // 遍歷 tr 的各個 td if ($(this).find("input").val().length > 6){ $(this).find("input").attr("style","width:60px;text-align: center;border-color: red") throw "length"; return false; } if (!(reg.test($(this).find("input").val()))) { $(this).find("input").attr("style","width:60px;text-align: center;border-color: red") throw "test"; return false; } if ($(this).find("input").attr("name") == 'dewater' && $(this).find("input").val() >100) { $(this).find("input").attr("style","width:60px;text-align: center;border-color: red") throw "big"; return false; } if (($(this).find("input").attr("name") == 'singleFloor' && !(zhenreg.test($(this).find("input").val()))) || ($(this).find("input").attr("name") == 'singleUpper' && !(zhenreg.test($(this).find("input").val()))) || ($(this).find("input").attr("name") == 'singleQuota' && !(zhenreg.test($(this).find("input").val()))) ) { $(this).find("input").attr("style","width:60px;text-align: center;border-color: red") throw "zhen"; return false; } jsonStr += "\"" + $(this).find("input").attr("name") + "\":" + $(this).find("input").val() + "," }); jsonStr = (jsonStr.substring(jsonStr.length - 1) == ',') ? jsonStr.substring(0, jsonStr.length - 1) : jsonStr; jsonStr += "},"; } }); $('#dataTable2 tr').each(function (i) { if ($(this).children('td').length > 0) { jsonStr += "{" $(this).children('td').each(function (j) { // 遍歷 tr 的各個 td if ($(this).find("input").val().length > 6){ $(this).find("input").attr("style","width:60px;text-align: center;border-color: red") throw "length"; return false; } if (!(reg.test($(this).find("input").val()))) { $(this).find("input").attr("style","width:60px;text-align: center;border-color: red") throw "test"; return false; } if ($(this).find("input").attr("name") == 'dewater' && $(this).find("input").val() >100) { $(this).find("input").attr("style","width:60px;text-align: center;border-color: red") throw "big"; return false; } if (($(this).find("input").attr("name") == 'singleFloor' && !(zhenreg.test($(this).find("input").val()))) || ($(this).find("input").attr("name") == 'singleUpper' && !(zhenreg.test($(this).find("input").val()))) || ($(this).find("input").attr("name") == 'singleQuota' && !(zhenreg.test($(this).find("input").val()))) ) { $(this).find("input").attr("style","width:60px;text-align: center;border-color: red") throw "zhen"; return false; } jsonStr += "\"" + $(this).find("input").attr("name") + "\":" + $(this).find("input").val() + "," }); jsonStr = (jsonStr.substring(jsonStr.length - 1) == ',') ? jsonStr.substring(0, jsonStr.length - 1) : jsonStr; jsonStr += "},"; } }); jsonStr = (jsonStr.substring(jsonStr.length - 1) == ',') ? jsonStr.substring(0, jsonStr.length - 1) : jsonStr; jsonStr += "]" }catch (e) { if (e.valueOf() == 'length'){ Feng.alert("長度不能超過6!"); }else if (e.valueOf() == 'test') { Feng.alert("請輸入正確資料!") }else if (e.valueOf() == 'zhen') { Feng.alert("請輸入正整數!") } else if (e.valueOf() == 'big') { Feng.alert("退水不能超過100%!") } return; } $.ajax({ url:'/pressureseting/updatepressureseting', type:'POST', data:{"jsonStr":jsonStr}, dataType:'json', success:function(data){ if (data.code == 200){ PressureSetingInfoDlg.close(); } } }); } </script> <script src="${ctxPath}/static/modular/games/pressureSeting/pressureSeting_info.js"></script> <style type="text/css"> .nax{ text-align: center; width: 1000px; display: flex; } .nax table{ width: 500px; } </style>