两个下拉框选择后取出这两个框的区间值

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script src="jquery-1.8.3.min.js"></script>
  <script>
  function changeFun(val)
    {//$("#EduMax option").length
        $("#EduMax option").eq("").attr('selected', true);

            for (var i = $("#EduMax option").length; i >= 0; i--) {
                //    alert($("#EduMax option").eq(i).val());
                $("#EduMax option").eq(i).show();
            }
            if (val != "") {
                for (var i = val ; i <= $("#EduMax option").length; i++) {
                //    alert($("#EduMax option").eq(i).val());
                $("#EduMax option").eq(i).hide();
            }

        }
    }
    function GetText() {
        var min = $("#EduMin").val();//$("#EduMin")[0].selectedIndex: 3
        var max = $("#EduMax").val();
        var result = new Array();
        if ($("#EduMin")[0].selectedIndex == 0 && $("#EduMax")[0].selectedIndex != 0)//左边没选 右边选了
        {
            for (var i = max ; i < $("#EduMax option").length ; i++) {//不包含 左边 ‘请选择’
                result.push($("#EduMax option").eq(i)[0].innerHTML);
            }
        }
        else if ($("#EduMin")[0].selectedIndex != 0 && $("#EduMax")[0].selectedIndex == 0)//左边选了 右边没选
        {
            for (var i = max + 1 ; i <= min ; i++) {//不包含 右边 ‘请选择’
                result.push($("#EduMax option").eq(i)[0].innerHTML);
            }
        }
        else if ($("#EduMin")[0].selectedIndex == 0 && $("#EduMax")[0].selectedIndex == 0)
        {
        }
        else {
            for (var i = max ; i <= min ; i++) {
                result.push($("#EduMax option").eq(i)[0].innerHTML);
            }
        }
        alert(result.join(','));
    }


  </script>
 </head>

 <body>
  <select id="EduMin" onchange="javascript:changeFun(this.value)">
            <option value="">请选择</option>
            <option value="1">博士生</option>
            <option value="2">研究生</option>
            <option value="3">本科</option>
            <option value="4">大专</option>
            <option value="5">高职</option>
            <option value="6">初中</option>
            <option value="7">小学</option>
        </select>
            <select id="EduMax" onChange="javascript:GetText()">
            <option value="">请选择</option>
            <option value="1">博士生</option>
            <option value="2">研究生</option>
            <option value="3">本科</option>
            <option value="4">大专</option>
            <option value="5">高职</option>
            <option value="6">初中</option>
            <option value="7">小学</option>
        </select>
 </body>
</html>

 

js和Jquery获取选中select值和文本

JS:

<body>
<select name="PaymentType" style="width:110px" >
<option value="">请选择 </option>
<option value="001">月付</option>
<option value="002">半年付</option>
<option value="003">年付</option>
</select>
<script language="javascript">
function Gettext(obj){
var txt=obj.options[obj.options.selectedIndex].text;
alert(txt)
}
function Getvaule(obj){
var val=obj.options[obj.options.selectedIndex].value;
alert(val)
}
</script>
</body>

 

 Jquery:

<body>
<select name="PaymentType" style="width:110px" >
<option value="">请选择 </option>
<option value="001">月付</option>
<option value="002">半年付</option>
<option value="003">年付</option>
</select>
<script language="javascript">
function Gettext(obj){
var txt=$(obj).find("option:selected").text();
alert(txt)
}
function Getvaule(obj){
var val=$(obj).find("option:selected").val();
alert(val)
}
</script>
</body>

posted @ 2015-08-25 07:50  BloggerSb  阅读(453)  评论(0编辑  收藏  举报