如何获得select被选中option的value和text和......
我想获取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和......的更多相关文章
- 如何获得select被选中option的value和text
如何获得select被选中option的value和text 一:JavaScript原生的方法 1:拿到select对象: var myselect=document.getElementById( ...
- 26.如何获得select被选中option的value和text
如何获得select被选中option的value和text 一:JavaScript原生的方法 1:拿到select对象: var myselect=document.getElementById( ...
- jquery 获取下拉框 某个text='xxx'的option的属性 非选中 如何获得select被选中option的value和text和......
jquery 获取下拉框 某个text='xxx'的option的属性 非选中 5 jquery 获取下拉框 text='1'的 option 的value 属性值 我写的var t= $(" ...
- 获得select被选中option的value和text
一:JavaScript原生的方法 1:得到select对象: var myselect=document.getElementById(“test”); 2:得到选中项的索引:var index=m ...
- 如何获得select被选中option的value和text和其他属性值
比如这个: <select id="select"> <option value="A" url="http://www.baidu ...
- 使用vxe table组件时,edit-render配置$select',选中option后关闭cell的激活状态,显示选中option的value问题
在我的项目中使用vxe table组件时,edit-render配置{name: '$select', options: [{label:"脉搏",value:"maib ...
- select 获取选中option的值方法,选中option方法
options=$("#Select option:selected"); options.attr('name');options.val(); options.text(); ...
- select获取到option的value和text方法
function getSelectval(id){ var selId = document.getElementById(id); //获取select的id var seleIndex =sel ...
- 分享一个option样式传递给select当前选中样式
今天遇到一个很是纠结的问题,需求又改了!原生的select给option加样式,结果发现select选中仍是默认样式,如下图:
随机推荐
- 036_监控 HTTP 服务器的状态(测试返回码)
#!/bin/bash #设置变量,url 为你需要检测的目标网站的网址(IP 或域名)url=http://192.168.4.5/index.html #定义函数 check_http:#使用 c ...
- webservice应用+建议不用webservice
webservice应用 1.分布式应用的集成(应用程序之间的集成) 2.软件重用 将一个软件的功能以webservice方式暴露出来,达到软件重用.例如上边分析天气预报,将天气查询功能以webser ...
- Java+web+上传文件夹
用JAVA实现大文件上传及显示进度信息 ---解析HTTP MultiPart协议 (本文提供全部源码下载,请访问 https://github.com/1269085759/up6-jsp-mysq ...
- 【概率论】3-2:连续分布(Continuous Distributions)
title: [概率论]3-2:连续分布(Continuous Distributions) categories: Mathematic Probability keywords: Continuo ...
- springboot之搭建第一个helloworld程序
1.下载基本框架 在网站:https://start.spring.io/ 全部默认,基本没有改动 选择依赖,当然也可以自己在pom.xml加,我们直接在这里选择. 只选择Spring Web Sta ...
- slax中改变终端字体
修改~/.Xresources文件 ! English font Xterm*faceName: DejaVu Sans Mono=True:size=16 修改颜色: ! colos XT ...
- Job for keepalived.service failed because the control process exited with error code. See "systemctl status keepalived.service" and "journalctl -xe" for details.
解决方案 https://blog.csdn.net/zt15732625878/article/details/86493096
- mysql密码设置为空怎么办?
由于很多童鞋安装使用MySQL时,安装时没有设置密码,或者像我一样图省事设置密码为空,想为其设置新密码: 1.点击 开始------>运行----在弹出的对话框中输入cmd 如下图: 2.使用 ...
- 在CSS中定义【导航栏】超链接样式
1.案例css代码 <style> .divcss5 a:link{ color:#F00}/* 链接默认为红色 */ .divcss5 a:hover{ color:#000}/* 鼠标 ...
- VLC-DSS搭建直播系统中链路断开影响测试
VLC-DSS搭建直播系统中链路断开影响测试 系统环境搭建如图所示.计算机77上运行VLC从摄像机51上取流,推送给一级DSS服务器30:二级DSS服务器78从一级DSS服务器30上取流转发.(其配置 ...