我是javascript的新手......如何获得< select>的价值在这个函数的JavaScript中 [英] I am new in javascript...How do I get value of <select> in javascript in this function

查看:59
本文介绍了我是javascript的新手......如何获得< select>的价值在这个函数的JavaScript中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function validateField() {

            var Inp = document.getElementsByTagName("input");
            var s = document.getElementsByTagName("select");
            for (var i = 0; i < Inp.length + s.length; i++) {
                if (Inp[i].getAttribute("isvalid") == "In") {
                    if (Inp[i].value == "") {
                        alert("Pls enter value");
                    }
                }
                else {
                    if (s[i].value == "Select") {
                        alert("Pls select city");
                    }
                }
            }
        }

推荐答案

var selected_index = oForm.elements["country"].selectedIndex;

if(selected_index > 0)
{
   var selected_option_value = oForm.elements["country"].options[selected_index].value;
   var selected_option_text = oForm.elements["country"].options[selected_index].text;
}
else
{
   alert('Please select a country from the drop down list');
}


这篇关于我是javascript的新手......如何获得&lt; select&gt;的价值在这个函数的JavaScript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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