1. 程式人生 > >使用layer彈窗提交表單時判斷表單是否輸入為空

使用layer彈窗提交表單時判斷表單是否輸入為空

使用layer彈窗提交表單時判斷表單是否輸入為空

  1. 獲得 layer 檔案包後,解壓並將 layer 整個資料夾(不要拆分結構) 存放到你專案的任意目錄,使用時,只需引入 layer.js 即可
  2. 使用時一定他要先引入jq1.8,或者以上版本!!!
  3. 下面是提交表單的實列
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"
/> <title></title> <script src="__STATIC__/js/mui.min.js"></script> <link href="__STATIC__/css/mui.min.css" rel="stylesheet"/> <script src="__STATIC__/layer/jquery-2.2.4.min.js"></script> <script src="__STATIC__/layer/layer.js"></script>
<script type="text/javascript" charset="utf-8"> mui.init(); </script> </head> <body> <center> <ul class="mui-table-view"> <li class="mui-table-view-cell">商品入庫</li> </ul>
</center> <form action="{:url('order')}" method="post" class="mui-input-group"> <div class="mui-input-row"> <label>商品單號:</label> <input type="text" class="mui-input-clear" placeholder=" 請輸入使用者名稱" name="order" id="order"> </div> <div class="mui-input-row"> <label>商品名稱:</label> <input type="text" class="mui-input-clear" placeholder=" 請輸入使用者名稱" name="name" id="name"> </div> <div class="mui-input-row"> <label>商品單價:</label> <input type="text" class="mui-input-clear" placeholder=" 請輸入使用者名稱" name="money" id="money"> </div> <div class="mui-input-row"> <label>商品庫存:</label> <input type="text" class="mui-input-clear" placeholder=" 請輸入使用者名稱" name="stock" id="stock"> </div> <div class="mui-input-row"> <label>商品備註:</label> <input type="text" class="mui-input-clear" placeholder=" 請輸入密碼" name="remarks" id="remarks"> </div> <div class="mui-button-row"> <button type="submit" class="mui-btn mui-btn-primary" id="cx">確認</button> </div> </form> <script type="text/javascript"> $(document).ready(function(){ $('#cx').click(function(){ var $1 = $.trim($('#order').val()); var $2 = $.trim($("#name").val()); var $3 = $.trim($("#money").val()); var $4 = $.trim($("#stock").val()); var $5 = $.trim($("#remarks").val()); if($1 == ''){ layer.msg('商品單號不能為空',function() {time:2000}); return false; } if($2 == ''){ layer.msg('請輸入商品名稱!',function() {time:2000}); return false; } if($3 == ''){ layer.msg('請輸入商品單價!',function() {time:2000}); return false; } if($4 == ''){ layer.msg('請輸入商品庫存!',function() {time:2000}); return false; } }); }); </script> </body> </html>