比如这个:

<select id="select">
<option value="A" url="http://www.baidu.com">第一个option</option>
<option value="B" url="http://www.qq.com">第二个option</option>
</select>
  • 1
  • 2
  • 3
  • 4

一:JavaScript原生的方法

1:拿到select对象: var myselect=document.getElementById("select");

2:拿到选中项的索引:var index=myselect.selectedIndex ; // selectedIndex代表的是你所选中项的index

3:拿到选中项options的value: myselect.options[index].value;

4:拿到选中项options的text: myselect.options[index].text;

5:拿到选中项的其他值,比如这里的url: myselect.options[index].getAttribute('url');

二:jQuery方法

1:var options=$("#select option:selected"); //获取选中的项

2:alert(options.val()); //拿到选中项的值

3:alert(options.text()); //拿到选中项的文本

4:alert(options.attr('url')); //拿到选中项的url值

如何获得select被选中option的value和text和其他属性值的更多相关文章

  1. 如何获得select被选中option的value和text

    如何获得select被选中option的value和text 一:JavaScript原生的方法 1:拿到select对象: var myselect=document.getElementById( ...

  2. 26.如何获得select被选中option的value和text

    如何获得select被选中option的value和text 一:JavaScript原生的方法 1:拿到select对象: var myselect=document.getElementById( ...

  3. jquery 获取下拉框 某个text='xxx'的option的属性 非选中 如何获得select被选中option的value和text和......

    jquery 获取下拉框 某个text='xxx'的option的属性 非选中 5 jquery 获取下拉框 text='1'的 option 的value 属性值 我写的var t= $(" ...

  4. 如何获得select被选中option的value和text和......

    我想获取select选中的value,或者text,或者…… 比如这个: <select id="select"> <option value="A&q ...

  5. 获得select被选中option的value和text

    一:JavaScript原生的方法 1:得到select对象: var myselect=document.getElementById(“test”); 2:得到选中项的索引:var index=m ...

  6. 使用vxe table组件时,edit-render配置$select',选中option后关闭cell的激活状态,显示选中option的value问题

    在我的项目中使用vxe table组件时,edit-render配置{name: '$select', options: [{label:"脉搏",value:"maib ...

  7. select初始化添加option,通过标签给出回显值,由于回显值和初始化值option中有一个值重复,去重等问题!

    第一张图片: 第二张图片 /** *该方法是为了去重,所谓去重就是 因为回显给select附上了值并设置为selected选中状态,而在我们初始化所有的select添加option元素中于回显的值重复 ...

  8. select 获取选中option的值方法,选中option方法

    options=$("#Select option:selected"); options.attr('name');options.val(); options.text(); ...

  9. select获取到option的value和text方法

    function getSelectval(id){ var selId = document.getElementById(id); //获取select的id var seleIndex =sel ...

随机推荐

  1. EL作用域对象

    EL与jsp的作用域对象对应关系,,,,,及EL具体作用域对象介绍,如下

  2. 77. Combinations (JAVA)

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  3. shell脚本之删除内容相同的重复文件

    #!/bin/bash #!当前文件夹下,删除内容相同的重复文件,只保留重复文件中的一个. ls -lS --time-style=long-iso | awk 'BEGIN{ getline;get ...

  4. Spring Boot 学习杂记

    使用IntelliJ IDEA构建Spring Initializr

  5. Tomb Raider HihoCoder - 1829 (二进制枚举+暴力)(The 2018 ACM-ICPC Asia Beijing First Round Online Contest)

    Lara Croft, the fiercely independent daughter of a missing adventurer, must push herself beyond her ...

  6. ubuntu 16.04 安装Opencv-3.2.0_GPU 与 opencv_contrib-3.2.0

    1.准备依赖库 sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config ...

  7. Tomcat的3种部署方式

    tomcat部署的三种方式及优缺点对比 部署方法一:将编译成功的web项目直接放到webapps目录中(注意是编译成功的web项目,也可以是war包):   部署方式二:修改tomcat安装目录下的  ...

  8. enums应用详解

    枚举类: 获取枚举相关值:

  9. 【NOIP2014模拟11.3】噪音

    题目 FJ有M个牛棚,编号1至M,刚开始所有牛棚都是空的.FJ有N头牛,编号1至N,这N头牛按照编号从小到大依次排队走进牛棚,每一天只有一头奶牛走进牛棚.第i头奶牛选择走进第p[i]个牛棚.由于奶牛是 ...

  10. git的用法的总结

    git的基本用法(一) 1).git的初始化 --配置用户名和邮箱 不然后面无法提交 git config --global user.name "myname"; git con ...