jsp 回顯顯示select

實現根據不同查詢條件查詢列表的功能,如圖:


查詢條件要用form提交:


 <div class="lead well">
                                  <form name='form1'>
                                  提現類型:<select name="type"  size="1" style="width: 10%" id = "WithDrawType" οnchange="WithDrawTypeOnchange()">
                                  <option value ="">請選擇</option>
                                  <c:forEach items="${withDrawTypes}" var = "ty">
                                  <option value = "${ty.value}"
                                  <c:if test="${ty.value eq type}">
                                  selected = "selected"
                                  </c:if>> ${ty.description }</option>
                                  </c:forEach>

                                  </select>
                                  <span>
                                   提現渠道: <select name = "channel" size="1" style="width: 10%" id="WithdrawChannel">
                                  <option value ="">請選擇</option>
                                  <option value ="1" <c:if test="${1 eq channel }">selected </c:if>>支付寶</option>
                                  <option value ="2" <c:if test="${2 eq channel }">selected </c:if>>微信</option>
                                  </select>
                                  </span>
                                   <label style="width: 20px"></label>
                                    <input type="hidden" value = "${exHandle}" id = "exHandleId"/>
                                    <input class="btn btn-danger"  type = "button" value = "查詢" οnclick="Search()"/>
                                  </form>
   </div>

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

js:

  $(function() {
        WithDrawTypeOnchange();
    });


     function Search() {
        var exHandle = $("#exHandleId").val();
        if(exHandle == 'true') {
            $("form[name='form1']").attr("action",
"<c:url value='/withdraw/exlist'/>");
        }else {
        $("form[name='form1']").attr("action",
"<c:url value='/withdraw/waitSpds'/>");
        }
$("form[name='form1']").submit();
    }
    
    function WithDrawTypeOnchange() {
    var type = $("#WithDrawType").find("option:selected").val();
    if(type != 0) {
       $("#WithdrawChannel").find("option[value='']").attr("selected",true);
       $("#WithdrawChannel").attr("disabled",true); 
    }else {
    $("#WithdrawChannel").attr("disabled",false); 
    }
    }

---------------------------------------------------------------------------------------------------------------

後端需要傳:

model.addAttribute("type", type);
model.addAttribute("channel", channel);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章