`
moqiang02
  • 浏览: 531377 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
文章分类
社区版块
存档分类
最新评论

this.options[selectedIndex]的使用

 
阅读更多
<select id="sel" onchange="javascript:getSelect();">
<option value="a">选择</option>
<option value="bdd">be</option>
<option value="c">ce</option>
<option value="d">de</option>
<option value="e">ee</option>
</select>
<script>
function getSelect() {
   //得到select下拉列表中option的value
   var optionValue = document.getElementById("sel").options[document.getElementById("sel").options.selectedIndex].value;
   //得到select下拉列表中option的text
   var optionText = document.getElementById("sel").options[document.getElementById("sel").options.selectedIndex].text; 
}
</script>

<select id="sele" onchange="javascript:getE();">
<option value="monday">星期一</option>
<option value="tuesday">星期二</option>
<option value="wednesday">星期三</option>
<option value="thursday">星期四</option>
<option value="friday">星期五</option>
</select>
<script>
function getE() {
   //我建议这里也像下面一些写,虽然这样写也可以获得数据
   var optionsValue = document.getElementById("sele").value;
   alert(optionsValue);
   var optionsText = document.getElementById("sele").options[document.getElementById("sele").options.selectedIndex].text;
   alert(optionsText);
}
</script>

分享到:
评论

相关推荐

    javascript 获取select下拉列表值的代码

    最关键的一段代码就是: 代码如下: onchange=”show(this.options[this.options.selectedIndex].value);” onchange=”show(this.options[this.options.selectedIndex].value);” show是一个自定义的函数名。 this....

    Select精美下拉框(漂亮)

    this.TitleTable.cells(0).childNodes(0).innerText = this.options[this.selectedIndex].innerText; if (this.bExpanded) this.toggleOptions(false); } function SS_toggleTitle (bReverse) { this....

    js select类

    return $(this).get(0).selectedIndex; } //获得当前选中项的文本 jQuery.fn.getSelectedText = function(){ if(this.size() == 0) return "下拉框中无选项"; else{ var index = this.getSelectedIndex...

    列表框互联

    onchange="ChangeSelect('../Ajax.asp?Type=1&Id;='+this.options[this.options.selectedIndex].value,'ztzlid');")

    js下弹出窗口的变通

    所以用的代码是: onChange=”window.open(this.options[this.selectedIndex].value,’_blank’)” 但这样很容易被屏蔽的…有更好的办法吗可以用变通的方法, 1.页面用&lt;a&gt;&lt;/a&gt; 2.document.getElementById(‘aa’)....

    ASP四级联动下拉菜单 (XML+Access)

    objSelect.onchange = Function( "var val = this.options[this.selectedIndex].value;BindSelect(m_sBaseSrc+val, '"+objSelect.ChildSelectName+"', '"+defaultVal+"');if(val!='')document.all....

    Vue.js获取被选择的option的value和text值方法

    如下所示: 1.获取option的value的值,watch option 控件时,或自动获取option的value的值。...select name=type onchange=show_sub(this.options[this.options.selectedIndex].value)&gt; 请选择主菜名 &lt;o

    JavaScript 基础问答 四

    二、导航功能增强   1. 下拉菜单中的链接(Links in Select Menu) Q:我如何实现在下拉菜单中链接到不同的页面?...self.location=this.options[this.selectedIndex].value”&gt; ”” selected&gt;Sele

    javascript经典年月日三级联动

    var YYYYvalue = document.form1.YYYY.options[document.form1.YYYY.selectedIndex].value; if (YYYYvalue == ""){ var e = document.form1.DD; optionsClear(e); return;} var n = MonHead[str - 1]; if (str ==...

    javaME实现的多功能菜单制作工具

    空闲时间用javaME制作的一个菜单小工具,构造函数如下public MenuList(String[] menuOptions, int SelectedIndex, int IntPositionX, int IntPositionY, int IntNumArrowhead) { this.IntSelectedIndex = ...

    JavaScript获取select中text值的方法

    本文实例讲述了JavaScript获取select中text值的...select name=parent_id onchange=setTitleAndLinkByGoodsCategory(this.value,this.options[this.selectedIndex].text); &gt; 请选择商品分类 家电 数码 &lt;optio

    JS分页效果JS分页效果

    if (this.page &gt; this.pageCount) this.page = this.pageCount; this.page = parseInt(this.page); this.pageCount = parseInt(this.pageCount); } showPages.prototype.createHtml = function(mode){ //生成html...

    一个实用的JSP分页代码

    select name=’page’ onChange=\”[removed].href='” + fileName + temp + “cur_page=’+this.options[this.selectedIndex].value\”&gt;”; 已经试过了,没问题 1.以下是实现分页的类PageResultSet 代码如下:...

    jquery.autocomplete 用户输入城市名、或拼音即可有匹配的提示

    this.selectedIndex=0; //输入时,一但有匹配的项,就默认选择第一项,这样,再按回车键,即可直接submit提交 jht添加 2011-07-20 $(".auto_selected_val").val(d); } 3. 当输入正确值,而不去选择相应提示项...

    .NET中实现客户端联动菜单 (无刷新)

    Ajax实现无刷新三联动下拉框 ... &lt;title&gt;Ajax实现无刷新三联动下拉框 ... &lt;SCRIPT language="javascript"&gt; //城市------------------------------ function cityResult() ... /// the contents of this method...

    js实现select跳转菜单新窗口效果代码分享(超简单)

    这是一款基于js实现select跳转菜单新...select onchange=window.open(this.options[this.selectedIndex].value) name=select&gt; &lt;option value=//www.jb51.net/jiaoben/ selected=selected&gt;脚本下载 &lt;option valu

    jQuery select控制插件

    和大家分享一下代码: JavaScript代码 代码如下: //得到select项的个数 jQuery.fn.size = function() { return jQuery(this).get(0).options.length; } //获得选中项的索引 jQuery.fn.getSelectedIndex = function()...

    Jquery操作Select 简单方便 一个js插件搞定

    这里是js的代码: 代码如下: jQuery.fn.size = function() { return jQuery(this).get(0).options.length; } //获得选中项的索引 jQuery.fn.getSelectedIndex = function() { return jQuery(this).get(0)....

    js获取下拉列表框option中的value和text的值示例代码

    在编程过程中,我们对下拉列表框的取值很多时候都是获取option中的value,但是也有需要获取显示在页面中的值的时候,例如想获得”...select onchange=”a(this.options[this.selectedIndex].innerText);”&gt;&lt;o

    下拉菜单点击实现连接跳转功能的js代码

    targ+”.location='”+selObj.options[selObj.selectedIndex].value+”‘”&#41;; if (restore) selObj.selectedIndex=0; } –&gt; 2.使用 代码如下: ”yq”&gt;校友会链接:&lt;/p&gt; &lt;p&gt; &lt;label&gt; &lt;select name=”select2″...

Global site tag (gtag.js) - Google Analytics