我想获取select选中的value,或者text,或者……

比如这个:

<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');
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

二: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

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

  5. 如何获得select被选中option的value和text和其他属性值

    比如这个: <select id="select"> <option value="A" url="http://www.baidu ...

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

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

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

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

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

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

  9. 分享一个option样式传递给select当前选中样式

    今天遇到一个很是纠结的问题,需求又改了!原生的select给option加样式,结果发现select选中仍是默认样式,如下图:

随机推荐

  1. 安装Discuz

    1.下载Discuz 版本文件 http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip 2.下载PHP http://window ...

  2. python print import使用

    >>> print("aaaa","bbbb")aaaa bbbb>>> print(1, 2, 3)1 2 3 为模块提供 ...

  3. 为什么margin:0 auto不能用于inline-block元素

    前言:今天一个实习生问我,为什么他对图片使用了margin:0 auto,但图片却没有居中,我让他换成对父元素使用text-align:center即可.为什么margin:0 auto对图片不起作用 ...

  4. [TJOI2019]唱、跳、rap和篮球

    嘟嘟嘟 TJ律师函警告 20分暴力比较好拿,因为每一种学生可以理解为无限多,那么总方案数就是\(C_{n} ^ {4}\),然后我们枚举至少讨论cxk的有几组,容斥即可. 需要注意的是,容斥的时候还要 ...

  5. ubuntu14.0 更改默认python为3.5 并安装tensorflow(cpu)

    转:http://blog.csdn.net/qq_27657429/article/details/53482595 第一:安装pip(如果有pip 跳过) #在ubuntu/Linux 64-bi ...

  6. ERRORS: ?: (corsheaders.E013) Origin '*' in CORS_ORIGIN_WHITELIST is missing scheme or netloc HINT:

    报错信息 ERRORS: ?: (corsheaders.E013) Origin '*' in CORS_ORIGIN_WHITELIST is missing scheme or netloc H ...

  7. js和jQuery实现的Ajax

    1. JS实现Ajax <!doctype html> <html lang="en"> <head> <meta charset=&qu ...

  8. allowMultiQueries=true mybatis 要多行sql执行,一定要注意

    allowMultiQueries=true 这个配置已经出现多次问题了,这次由于切换时多数据源,搞配置的同志不知道从哪里copy的配置,只换了我们的链接,我们之前配置了好多配置都丢失了,我的代码中有 ...

  9. JavaWeb_(Spring框架)用户登陆Spring整合到Servlet中

    一.使用servlet技术开发用户登陆功能 在MySQL中准备一个user表,表中增加一条假数据 使用Servlet实现用户登陆的功能 用户登陆的<from>表单 <form id= ...

  10. debian、ubuntu安装metasploit通用方法

    网上有很多方法让去github上下载安装,这方法的确可以但是特别慢,更新也特别慢,这里写下比较快的方法 1.添加kali源 vim /etc/apt/sources.list 在原有源的基础上添加国内 ...