zoukankan      html  css  js  c++  java
  • 两个下拉框选择后取出这两个框的区间值

    <!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="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="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>

  • 相关阅读:
    JQuery封装的ajax
    DOM节点操作
    ES6中的let和const
    CSS cursor 属性
    ui-router 视图嵌套时指定二级视图显示默认页面
    数组去重的几种方法
    basic_consume() got multiple values for keyword argument 'queue'
    perl改造成bash---结果写入xml
    springmvc 启动报 java.lang.NoSuchMethodError: org.springframework.core.GenericTypeResolver.resolveTypeArguments(Ljava/lang/Class;Ljava/lang/Class;)[Ljava/lang/Class;
    web项目部署名和项目名不一致
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/4756432.html
Copyright © 2011-2022 走看看