thymeleaf之下拉框回顯選中


#1.select下拉框取值
    <div class="form-group ">
        <label id="resource" for="resource" class="control-label col-lg-4">資源種類</label>
            <select id="item1" onchange="fn()" name="resource" th:value="${CloudDilatationDto.resource}"
             placeholder="請選擇" style="width: 200px;">
            <option value="">請選擇</option>
            <option value="服務器" th:selected="${CloudDilatationDto.resource == '服務器'}">服務器</option>
            <option value="內存"   th:selected="${CloudDilatationDto.resource == '內存'}">內存</option>
            <option value="存儲"   th:selected="${CloudDilatationDto.resource == '存儲'}">存儲</option>
            <option value="其他"   th:selected="${CloudDilatationDto.resource == '其他'}">其他</option>
        </select>
    </div>
    function  fn(){
       //var     name=$("#item1").find("option:selected").text(); //獲取文本值
       var     name=$("#item1").find("option:selected").val();  //獲取value值
           if(name !==null){
               version=name;
           }
    };

#2.從數據庫中查出,並在下拉框中回顯

參考鏈接:http://blog.csdn.net/song_de/article/details/33757939

function  fn(){
         $.ajax({
            url:"findCompany.json",
            type: "POST",
            success: function(data) {
                //var Str=JSON.stringify(data);
                //alert(Str);
                 for(var i=0;i<data.businessDeployDtoList.length;i++){
                     var option=document.createElement("option");
                     $(option).val(data.businessDeployDtoList[i].company);
                      $(option).text(data.businessDeployDtoList[i].company);
                     $('#item1').append(option);
                  }
             },
         });
     };

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM