比如这个:

<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. Jade学习(二)之语法规则上

    语法 ⚠️实例均结合node jade缩进代表层级 html <html></html> html <html> head <head> style & ...

  2. Logistic回归应用-预测马的死亡率

    Logistic回归应用-预测马的死亡率 本文所有代码均来自<机器学习实战>,数据也是 本例中的数据有以下几个特征: 部分指标比较主观.难以很好的定量测量,例如马的疼痛级别 数据集中有30 ...

  3. AGC015E Mr.Aoki Incubator

    atcoder luogu 首先可以考虑给一个人\(A\)染色.其他人被染色,要么被本来在后面的速度更快的人染色,要么被在前面的更慢的人染色.然后假设一个速度比最开始那个人慢的人\(B\)最后被染色了 ...

  4. centos安装mysql以及授权登录用户

    CentOS第一次安装MySQL的完整步骤 目录     1.官方安装文档    2.下载 Mysql yum包    3.安转软件源    4.安装mysql服务端    5.首先启动mysql   ...

  5. 一个常用的通过curl发送HTTP请求的函数

    function: function curl_get($url, $params) { return curl_http($url, $params, 'GET'); } function curl ...

  6. javaScript运动框架之匀速运动

    运动框架 1.在开始运动时,关闭已有定时器 2.把运动和停止隔开(if/else) 匀速运动的停止条件 运动终止条件:距离足够近 Demo代码 <!DOCTYPE html> <ht ...

  7. vue实现轮播图

    /* Start  基本样式*/ * {   margin: 0;   padding: 0; } ul {   list-style-type: none; } body {   font-size ...

  8. ajax传输数组类型的参数

    $.ajax({ type:"post", traditional: true, data:{arr:arr}, url:"${pageContext.request.c ...

  9. linux设置用户自定义别名

    设置用户自定义别名 首先进入当前用户家目录 我这里是 root 查看隐藏文件 注意到.bashrc文件,修改此可以用户自定义别名 保存退出,读入.bashrc设定 看看alias里有没 以后此用户就永 ...

  10. 微信获取token -1000

    最终翻看微信开发api找到需要去配置IP白名单.只需要配置访问来源IP即可.