Learn java front-end two form form submission methods

The first: the original way

Note: the style of the button tag is submit

<form action="/trans/doTrans.do" method="post">

    转出卡号:${cardNo}
    <br>
    转出卡号余额:${balance}元
    <br> <br>
    转入卡号:<input name="checkInCardNo" type="text">
    <br>
    转入卡号姓名:<input name="realName" type="text">
    <br>
    转出金额:<input name="money" type="text">

    <br>

    <button type="submit">确定转出</button>


</form>

The second: Jquery verification method

Note: the style of the button tag is the button
process: click submit, first trigger the submitForm() method, execute the verification and id selector, and finally submit the form.

 <script type="text/javascript">
    function submitForm() {
        if($("#t_in_cardNo").val().length!=8){
            alert("您输入的卡号位数不对!")
            return;
        }
        $("#transForm").submit();<!--此处是submit方法-->
    }
  </script>
  
  
         
<form id="transForm" class="am-form am-form-horizontal" action="/trans/doTrans.do" method="post">
    <div class="am-form-group">
        <label class="am-u-sm-3 am-form-label">转出卡号</label>
        <div class="am-u-sm-9">
            <input type="text" id="t_cardNo" readonly placeholder=${cardNo}>

        </div>
    </div>

    <div class="am-form-group">
        <label class="am-u-sm-3 am-form-label">转入卡号</label>
        <div class="am-u-sm-9">
            <input type="text" id="t_in_cardNo" pattern="[0-9]*" placeholder="请输入8位对方卡号"
                   name="checkInCardNo">
        </div>
    </div>

    <div class="am-form-group">
        <label class="am-u-sm-3 am-form-label">转账金额</label>
        <div class="am-u-sm-9">
            <input type="text" id="t_money" placeholder="输入转账金额" name="money">
        </div>
    </div>


    <div class="am-form-group">
        <div class="am-u-sm-9 am-u-sm-push-3">
            <button type="button" onclick="submitForm()" class="am-btn am-btn-primary">提交</button><!--此处为提交类型为button-->
        </div>
    </div>
</form>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324979174&siteId=291194637