注册 登录
编程论坛 JavaScript论坛

用 jquery 怎么得到被隐藏的 option 数量?

cai410579517 发布于 2014-05-28 15:59, 1428 次点击
做了一下select 不知道怎么判断可见option的数量 高手赐教
4 回复
#2
寒风中的细雨2014-05-29 13:29
程序代码:
<html>
<head>
<style type="text/css">
select{
    border: 3px red solid;
    padding: 5px;
    width: 200px;
    border-radius: 5px;
}
</style>
</head>
<body>
<select id="select">
    <option value="1">11</option>
    <option value="2">111</option>
    <option value="3">123</option>
</select>
<script type="text/javascript">
(function(){

    if (!document || !document.getElementById){
   

        console.log("error 1");
        return false;
    }
   

    var selectObj = document.getElementById("select");
    if (!selectObj){
   

        console.log("error 2");
        return false;
    }
   

    document.write("<br/><b>" + selectObj.length + "</b>");
   

    return true;
})();
</script>
</body>
</html>
#3
寒风中的细雨2014-05-29 13:30
输出option数量
#4
cai4105795172014-05-30 14:10
好长啊
#5
cai4105795172014-05-30 14:11
我换了一种方式 把问题解决了  同事把value 值写错了  搞了半天得不到值
1