Select selectedIndex 属性
定义和用法
selectedIndex 属性可设置或返回下拉列表中被选选项的索引号。
注意: 若允许多重选择,则仅会返回第一个被选选项的索引号。
语法
设置 selectedIndex 属性:
返回 selectedIndex 属性:
浏览器支持





所有主要浏览器都支持 selectedIndex 属性
实例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script>
function displayResult(){
var x=document.getElementById("mySelect").selectedIndex;
var y=document.getElementById("mySelect").options;
alert("索引: " + y[x].index + " is " + y[x].text);
}
</script>
</head>
<body>
<form>
选择你最喜欢的水果:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">显示索引</button>
</body>
</html>
来自:http://www.runoob.com/jsref/prop-select-selectedindex.html
Select selectedIndex 属性的更多相关文章
- selectedIndex 属性
selectedIndex 属性可设置或返回下拉列表中被选选项的索引号. 注释:若允许多重选择,则仅会返回第一个被选选项的索引号. 语法 selectObject.selectedIndex=numb ...
- iview select filterable属性使用下拉小bug
今天做项目时候在iview 原生自带的select中设置filterable,下拉时候可进行查询,但是发现选中载打开模态框每次都绑定上一次的值,解决方案就是在关闭弹框时候将this.$refs.sto ...
- select元素选择时间以及jQuery对select的属性操作
<select class="input04" id="1" name="in_class1" onchange="setc ...
- 如何设置 Panorama 控件的只读 SelectedIndex 属性?
在 OnNavigatedTo() 方法中设置: panoramaControl.DefaultItem = panoramaControl.Items[indexToSet];
- selectedIndex 属性可设置或返回下拉列表中被选选项的索引号。
转自:https://blog.csdn.net/xxj19950917/article/details/73002046
- jquery源码解析:attr,prop,attrHooks,propHooks详解
我们先来看一下jQuery中有多少个方法是用来操作元素属性的. 首先,看一下实例方法: 然后,看下静态方法(工具方法): 静态方法是内部使用的,我们外面使用的很少,实例方法才是对外的. 接下来,我们来 ...
- 解决HTML select控件 设置属性 disabled 后无法向后台传值的方法
大家都知道有时候修改数据的时候我们希望有一些数据是不可以修改的,通常情况下我们会将input框设置为 readonly , 但是 select 控件没有这个属性,需要使用另一个属性 disabled ...
- 深入浏览器兼容 细数jQuery Hooks 属性篇
关于钩子:http://www.cnblogs.com/aaronjs/p/3387906.html 本章的目的很简单,通过钩子函数更细节的了解浏览器差异与处理方案, 版本是2.0.3所以不兼容ie6 ...
- winFrom 常用控件属性及方法介绍
目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox(文本框)控件 4.RichTextBox控件 5.NumericUpDown控件 6.Button(按钮)控件 7.Gro ...
随机推荐
- Spring Eureka的使用入门
Eureka调度服务: Gradle依赖包: 基础框架依赖配置核心代码: buildscript { repositories { mavenCentral() } dependencies {cla ...
- 创建一个流(Stream)可以让Bitmap或Image保存到流里面
创建一个流(Stream)可以让Bitmap或Image保存到流里面 http://blog.csdn.net/angxiao/article/details/7481465 写文件流 ...
- dotnet体系结构
一.C#与.NET的关系 1.粗略地説,.net是一种在Windows平台上的编程架构————一种API. 2.C#编译器专门用于.net,这表示用C#编写的所有代码总是使用.NET Framewor ...
- 栈 - 20 Valid Parentheses, 150 Evaluate Reverse Polish Notation
class Solution { public: bool isValid(string s) { stack<char> st; ; i<s.size(); i++){ if(s[ ...
- C#工具类之素数扩展类
/// <summary> /// 素数帮忙类 /// 本类是从.net源码 类 internal static class HashHelpers 类里抽取相应的代码 /// https ...
- B. Divisors of Two Integers
B. Divisors of Two Integers time limit per test 1 second memory limit per test 256 megabytes input s ...
- python3.6 request模块和ddt模块的安装
1.1用cmd命令进到python的安装目录的Scripts文件夹 1.2.然后输入 pip install requests,出现以下提示,说明安装成功 2.安装ddt步骤一样,只是把pip ins ...
- 第三次 Scrum Meeting
第三次 Scrum Meeting 写在前面 会议时间 会议时长 会议地点 2019/4/7 20:00 60min 新主楼G411 附Github仓库:WEDO 例会照片 工作情况总结(4.5-4. ...
- D15 模块
模块
- vue中使用对非表单元素使用contenteditable的问题
先说下问题,再上解决方案: span编辑时有多余空格和回车会影响样式(我用的是span便以此为例) 代码:(有换行符) 效果图: 代码:(无换行符) 效果图: 当在span标签的contentedit ...