zoukankan      html  css  js  c++  java
  • jQuery获取各种标签的文本和value值

    <select id="test">
      <option value ="volvo">Volvo</option>
      <option value ="saab">Saab</option>
      <option value="opel">Opel</option>
      <option value="audi">Audi</option>
    </select>
     
    获取select 选中的 text :
        $("#test").find("option:selected").text();
     
    获取select选中的 value:
        $("#test").val();
     
    获取select选中的索引:
        $("#test").get(0).selectedindex;
     
    设置select:
    设置select 选中的索引:
        $("#test").get(0).selectedindex=index;//index为索引值
     
    设置select 选中的value:
        $("#test").attr("value","normal“);
        $("#test").val("normal");
        $("#test").get(0).value = value;
     
    设置select option项:
     
        $("#test").append("<option value='value'>text</option>");  //添加一项option
        $("#test").prepend("<option value='0'>请选择</option>"); //在前面插入一项option
        $("#test option:last").remove(); //删除索引值最大的option
        $("#test option[index='0']").remove();//删除索引值为0的option
        $("#test option[value='3']").remove(); //删除值为3的option
        $("#test option[text='4']").remove(); //删除text值为4的option
     
     
    清空 select:
     
        $("test").empty();

  • 相关阅读:
    java修改应用程序标题栏
    电动双轮车
    Oracle执行计划相关(待补充)
    SQL中IN和EXISTS用法的区别
    union all与union all
    equals与hashcode
    文件上传的整个流程
    adwords与adsence
    struts2文件上传大小
    为什么是UUID做主键
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11519853.html
Copyright © 2011-2022 走看看