zoukankan      html  css  js  c++  java
  • JQuery设置获取下拉菜单选项的值 多实例

    分享下JQuery如何设置获取下拉菜单某个选项的值,多种方法,值得收藏。

    JQuery获取和设置Select选项

    获取Select :
    获取select 选中的 text :
    $(“#ddlRegType”).find(“option:selected”).text();
    获取select选中的 value:
    $(“#ddlRegType “).val();
    获取select选中的索引:
    $(“#ddlRegType “).get(0).selectedIndex;
    设置select:
    设置select 选中的索引:
    $(“#ddlRegType “).get(0).selectedIndex=index;//index为索引值
    设置select 选中的value:
    $(“#ddlRegType “).attr(“value”,”Normal“);
    $(“#ddlRegType “).val(“Normal”);
    $(“#ddlRegType “).get(0).value = value;
    设置select 选中的text:
    var count=$(“#ddlRegType option”).length;
    for(var i=0;i<count;i++)
    { if($(“#ddlRegType “).get(0).options[i].text == text)
    { // www.jbxue.com
    $(“#ddlRegType “).get(0).options[i].selected = true;
    break;
    }
    }
    清空 Select:
    $(“#ddlRegType “).empty();

  • 相关阅读:
    装饰器和表达生成式
    函数
    字符编码
    函数基础
    列表,字典与集合
    Linux Semaphore
    tp5安装easyWeChat
    wx.request
    小程序设计规范
    小程序的概念和特点
  • 原文地址:https://www.cnblogs.com/cfinder010/p/3893608.html
Copyright © 2011-2022 走看看