zoukankan      html  css  js  c++  java
  • 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=" 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);
                      }
                 },
             });
         };

  • 相关阅读:
    滴滴日送400万红包,仅仅为人群不冷漠?
    C++提供的四种新式转换--const_cast dynamic_cast reinterpret_cast static_cast
    GreenDao开源ORM框架浅析
    Python 计数器
    Linux虚拟内存的添加
    Linux iptables
    Python set
    Python dict get items pop update
    Python contains
    Python reverse
  • 原文地址:https://www.cnblogs.com/Steven5007/p/7865202.html
Copyright © 2011-2022 走看看