Java脚本中HTML选择控件的访问值和所选文本 [英] Access Value and selected text of html select control in java script

查看:53
本文介绍了Java脚本中HTML选择控件的访问值和所选文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的选择控件.

I have a select control like this.

<script type="text/javascript">
        function countrychange() {
            var cou = document.getElementById('country').value;
            alert(cou);
        }
</script>





<select id="country" name="D1"  önchange="countrychange()">
        <option value="IN">India</option>
        <option value="US">USA</option>
</select>


当我更改任何国家/地区时,它将显示我的价值,但是我想这样显示,假设选择了Option-India,那么它应该向我显示印度.


When I change any country then it is displaying me it''s value, but I want to display like this, suppose Option-India selected, then it should show me India.

推荐答案

您是否熟悉Jquery ..?
或尝试这个
are you familiar with Jquery..?
or Try this
var name=document.getElementById('country')[document.getElementById('country').nodeType].innerHTML


var sel = document.getElementById('country');
var index = sel.selectedIndex;
var text = sel.options(index).text;
alert('the text is :'+ text + '\nthe value is : '+sel.value);


这篇关于Java脚本中HTML选择控件的访问值和所选文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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