• 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"); 
  • 相关阅读:
    数据分析入门_char01
    [转]在Goolge安装谷歌插件Postman
    Ubutu 14.04 Fiddler Android抓包
    Ubuntu14.04 install appium
    【转】ubuntu修改时区和时间的方法
    MongoDB权威指南<2> 1-2 MongoDB 介绍
    python数据类型-字典
    python数据类型-列表
    python数据类型-字符串
    python编码以及格式化输出
  • 原文地址:https://www.cnblogs.com/swack/p/5047946.html
Copyright © 2020-2023  润新知