3个级联select,s1,s2,s3,如果s3有值返回s3,否则返回s2,如果s2为空则返回s1,试问这样的取值应该怎么取?
我的想法是获取所有被选中的select的last-child,但是根据opstion=selected返回select集合我却不会弄,求高手指点

解决方案 »

  1.   


    $('#s3').val() || $('#s2').val() || $('#s1').val();
      

  2.   

    <select id="select1">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    </select>$("#select1 option:selected").val();第二级和第三级同理
      

  3.   


    function selects(num) {  
        if ($('#s' + num).val()) {  
            return $('#s' + num).val();  
        } else {  
            return selects($('#s' + num - 1);  
        }  
    }
      

  4.   

         function pick_select_value(){
                for (var i = $("select").length - 1; i >= 0; i--) {
                    if ($("select").eq(i).find("option:selected").val()) {
                        return $("select").eq(i).find("option:selected").val();
                        break;
                    }
                }
              }