zoukankan      html  css  js  c++  java
  • HTML select 操作

    今天遇到一个问题,就是想设置select的默认选择项。但是试了很多方法都不行:

    <fieldset data-role="contractstatus">  
            <label for="switch">是否中标:</label>
            <select name="switch" id="switch">
              <option value="1">NO</option>
              <option value="2">YES</option>
            </select>
            </fieldset>

    jquery脚本1:

     <script type="text/javascript">
                $(function(){
                    try{
                    <%   int k=Integer.parseInt(p_status); 
                            if(k==1){
                    %>
                    //$("#switch option[text='YES']").attr("selected", "selected");
                    //$("#switch").val("2");
                    $("#switch").find("option[value='1']").attr("selected","selected");
                    //$("#switch").find("option[value='2']").focus();
                    <%
                            }else if(i==2){
                    %>
                    $("#switch option[text='YES']").attr("selected", "selected"HTML源码编辑器);
                    <%
                            }
                    %>
                    }catch(e){}
                });
    </script> 

    jquery脚本2:

    <script type="text/javascript">
                $(function(){
                    setTimeout(function() { 
                    <%   int k=Integer.parseInt(p_status); 
                            if(k==1){
                    %>
                    $("#switch option[text='YES']").attr("selected", true);
                    //$("#switch").val("2");
                    <%
                            }else if(i==2){
                    %>
                    $("#switch option[text='YES']").attr("selected", "selected");
                    <%
                            }
                    %>
                    }, 1);
                });
    </script>

    试了各种方法都不行

    最后发现,其实select已经改变了,只是对应的文本变,所以只需修改文本就行。

    $("#switch option[value='1']").attr("selected", "selected");
    //$("#switch").selectmenu("refresh", true);
    $("#switch").slider("refresh"); 
  • 相关阅读:
    pyDNS学习
    BUUCTF password
    攻防世界 easy-apk
    Android Normal writeup
    Jarvis OJ
    阿里云服务器连接(安装)宝塔面板
    bmp格式转为jpeg格式文件
    课设记录-Day15
    课设记录-Day14
    课设记录-Day13
  • 原文地址:https://www.cnblogs.com/swack/p/5047946.html
Copyright © 2011-2022 走看看