如何从ComboBox获得价值 [英] How To get Value From ComboBox

查看:65
本文介绍了如何从ComboBox获得价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <  选择    id   ="    ;" <  选项 >  1 <  /option  > 
                            <  选项 >  2 <  /option  > 
                            <  选项 >  3 <  /option  > 
<  /selecte  >  



我想获取onChange()发生时的值,并选择警报回复我!!!
感谢

解决方案

< script type = " 文本/javascript" language =   javascript">
函数 getalert()
{
 var  str = 文档 .getElementById("  Select2").value;
  警报(str);
}
</script> 


 <  选择    id   ="      önchange   getalert()" <  选项 >  1 <  /option  > 
                            <  选项 >  2 <  /option  > 
                            <  选项 >  3 <  /option  > 
<  /select  >  


您可以获取当前值或选定的索引:

 sel = 文档 .getElementById(" );
值= sel.value;
索引= sel.selectedIndex;
// 使用任何您想要的东西 



对于选择onchange,它是在您按Enter或单击所选项目时调用的,而不是在更改选择时调用的,这是很合理的事情.

请参阅:
http://www.w3schools.com/jsref/dom_obj_select.asp [<select id="Select2" ;"> <option>1</option> <option>2</option> <option>3</option> </selecte>



i Want To Get When onChange() occured Value selected with alert response me!!!
thanks

<script type="text/javascript" language="javascript">
function getalert()
{
var str=document.getElementById("Select2").value;
  alert(str);
}
</script>


<select id="Select2"  önchange="getalert()">
                            <option>1</option>
                            <option>2</option>
                            <option>3</option>
</select>


You can get either current value or selected index:

sel = document.getElementById("Select2");
value = sel.value;
index = sel.selectedIndex;
//use whatever you want



As to the select onchange, it is invoked when you press Enter or click on selected item, not when you change the selection, which a is pretty reasonable thing.

Please see:
http://www.w3schools.com/jsref/dom_obj_select.asp[^].

—SA


这篇关于如何从ComboBox获得价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆