我想获取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. MySQL Bug#67718 浅谈B+树索引的分裂优化

    原文链接:http://hedengcheng.com/?p=525 问题背景 今天,看到Twitter的DBA团队发布了其最新的MySQL分支:Changes in Twitter MySQL 5. ...

  2. 帝国CMS 7.2-插件包整合

    版权所有 2009-2019 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/index.aspx 产品首页:http://www.ncmem.com/weba ...

  3. 51 Nod 1700 首尾排序法

    1700 首尾排序法 有一个长度为n的数组 p1, p2, p3, ⋯, pnp1, p2, p3, ⋯, pn ,里面只包含1到n的整数,且每个数字都不一样.现在要对这个数组进行从小到大排序,排序的 ...

  4. Cogs 1500. 误差曲线(三分)

    误差曲线 ★★ 输入文件:errorcurves.in 输出文件:errorcurves.out 评测插件 时间限制:1 s 内存限制:256 MB [题目描述] Josephina是一名聪明的妹子, ...

  5. qt5.6.1 +vs2015 自定义控件 不在designer显示

    qt designer 不显示自定义插件, qt5.6.1下在bin下点击designer.exe 打开qdesigner 点击帮助- 关于插件. 显示: 在vs2015 窗口中点击qt vs too ...

  6. gcc 带参数进行编译

    gcc -DYES -o helloyes hello.c 在hello.c中存在 #ifdefine YES ........

  7. javascript监听浏览器前进后退

    window.addEventListener("popstate", function () { backStatus=true; return; })

  8. linux安装后需要进行的一些基本设置

    修改网络: 在终端中输入:vi /etc/sysconfig/network-scripts/ifcfg-ens33 然后重启网络服务:systemctl restart network.servic ...

  9. CPU、io、mem之间的关系

    https://blog.csdn.net/weixin_38250126/article/details/83412749 https://blog.csdn.net/joeyon1985/arti ...

  10. Android控件RecyclerView的基本用法

    Android控件RecyclerView的基本用法 转 https://www.jianshu.com/p/e71a4b73098f   github: https://github.com/Cym ...