JS获取select的value和text值的简单实例
<select id = "cityList" >
<select id = "selectId" >
<option value = "0">第0个</option>
</select>
<script>
var selectObj = document.getElementById('selectId');
// 通过对象添加option
selectId.add(new Option("第一个","1"))
selectId.add(new Option("第二个","2"))
// 通过id添加option
selectId.add(new Option("第三个","3"))
selectId.add(new Option("第四个","4"))
// 通过id添加方法(也可以通过对象添加方法)
selectId.onchange = function(){
// 通过对象获取value和text
alert(selectObj.value);
alert(selectObj.options[selectObj.selectedIndex].text);
// 通过 id 获取value和text
alert(selectId.value);
alert(selectId.options[selectId.selectedIndex].text);
// 还可以通过this获取value和text
alert(this.value);
alert(this.options[this.selectedIndex].text);
};
</script>
相关推荐
-
js获取当前select 元素值的代码
如果 select 元素下的所有 option 元素均没有指定 selected 属性,会默认选中第一个. 可以通过 select.selectedIndex 获取到选中的 option 元素的索引. 可以通过 select.options[select.selectedIndex] 获取到选中的 option 元素. option 元素 <option selected="selected" value="value3">text3</optio
-
js 获取当前select元素值的代码
1.如果 select 元素下的所有 option 元素均没有指定 selected 属性,会默认选中第一个. 2.可以通过 select.selectedIndex 获取到选中的 option 元素的索引. 3.可以通过 select.options[select.selectedIndex] 获取到选中的 option 元素. 4.option 元素 <option selected="selected" value="value3">text3&l
-
js获取select选中的option的text示例代码
javascript 复制代码 代码如下: var item = document.getElementById(""); var text = item.options[item.selectedIndex].text; jQuery 复制代码 代码如下: var text = $("#selector")[0].options[$("#selector")[0].selectedIndex].text
-
JavaScript获取select中text值的方法
本文实例讲述了JavaScript获取select中text值的方法.分享给大家供大家参考,具体如下: 别的不说,先看代码: 方法一: <select name="parent_id" onchange="setTitleAndLinkByGoodsCategory(this.value,this.options[this.selectedIndex].text);" > <option value="0">请选择商品分类
-
JS 获取select(多选下拉)中所选值的示例代码
复制代码 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author&q
-
JS获取select-option-text_value的方法
HTML代码: 复制代码 代码如下: <select id="month" onchange="selectInput(this)"> <option value="01">January</option> <option value="02">February</option> <option value="03"&
-
js select 标签选定项的值获取代码
11 22 33 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] onchange="change(this)" 在这个时候 this代表select这个标签本身
-
js添加select下默认的option的value和text的方法
<pre name="code" class="java"> jsp 中的下拉框标签: <s:select name="sjx" id="sjx" list="sjxList" listKey="BM" listValue="MC" size="20" cssStyle="width:100%;height:70px;
-
jquery及原生js获取select下拉框选中的值示例
现在有一id=test的下拉框,怎么拿到选中的那个值呢? 分别使用javascript原生的方法和jquery方法 复制代码 代码如下: <select id="test" name=""> <option value="1">text1</option> <option value="2">text2</option> </select> 一:javas
-
js获取select标签选中值的两种方式
复制代码 代码如下: var obj = document.getElementByIdx_x("testSelect"); //定位idvar index = obj.selectedIndex; // 选中索引var text = obj.options[index].text; // 选中文本var value = obj.options[index].value; // 选中值jQuery中获得选中select值第一种方式$('#testSelect option:select
-
获取select的value、text值的简单示例(jquery与javascript)
1.jquery //获取value值 $("#ddlSubmodel").val(); //获取text值 $("#ddlSubmodel").find("option:selected").text(); 2.javascript //获取value值 document.getElementById("ddlSubmodel").value; //获取text值 var select = document.getEleme
-
获取select元素被选中的文本内容的js代码
复制代码 代码如下: var sel=document.getElementById(id);//select元素的id var index=sel.selectedIndex;//获取被选中的option的索引 var textsel= sel.options[index].text;//获取相应的option的内容
-
javascript 获取select下拉列表值的代码
比如,在使用DWR的时候,如果你想传递下拉框的参数到后台的话,此时就需要先获取到下拉框的值了. 其实想要获取到下拉框的值是很简单的. 最关键的一段代码就是: 复制代码 代码如下: onchange="show(this.options[this.options.selectedIndex].value);" onchange="show(this.options[this.options.selectedIndex].value);" show是一个自定义的函数名.
随机推荐
- 关于extjs treepanel复选框选中父节点与子节点的问题
- iOS自定义日历控件的简单实现过程
- iOS图片实现可拉伸不变形的处理操作
- java原装代码完成pdf在线预览和pdf打印及下载
- jquery结合CSS使用validate实现漂亮的验证
- 解析 thinkphp 框架中的部分方法
- asp中一段防SQL注入的通用脚本
- c++ const引用与非const引用介绍
- JavaScript中this详解
- 利用纯Vue.js构建Bootstrap组件
- 原生js FileReader对象实现图片上传本地预览效果
- 虚拟主机MySQL数据库的备份与还原的方法
- 用户目录上只用了几十M ,为什么在后台显示用了500M了呢
- MyBatis中OGNL的使用教程详解
- 浅谈hibernate之映射文件VS映射注解
- Java 高并发一:前言
- 下载软件后使用c#获取文件的md5码示例
- php防注
- 微信公众平台开发教程(三) 基础框架搭建
- Android中一种效果奇好的混音方法详解