Javascript-如何隐藏下拉菜单控件(如果为空) [英] Javascript - How to hide a drop down control if it's empty

查看:75
本文介绍了Javascript-如何隐藏下拉菜单控件(如果为空)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上有一个层叠下拉列表.用户选择文档类型",大多数文档类型具有类别".但是,如果文档类型没有类别,那么我想隐藏类别下拉列表.有没有办法查看类别下拉列表(计算数组或其他内容)并隐藏类别控件(默认情况下,即使下拉列表没有任何值可供选择,该控件也始终显示选择值")

I have a cascade dropdown on a form. User selects Document Type and most of the document type has Category. However, if a doc type does not have category then I would like to hide the category drop down. Is there a way to see if category dropdown (calculate array or something) and hide category control (by default it always show Select a value even if the drop down does not have any value to select from)

到目前为止,我已经关注并想知道如何根据用户在文档类型下拉控件中选择的内容来评估类别下拉控件.

So far I have following and wondering how to evaluate category drop down control based on what user selected in the doc type drop down control.

NWF$(document).ready(function(){  
     var varDocType= NWF$('#' + jsDocTypes)// gets Doc Type control;
     varDocType.change(function(){  
          if(this.value !== null){  
            alert(varDocType.val());
            var varCategory = NWF$('#' + jsCategory)// gets Category control;
            alert(varCategory.val());
            if(varCategory == ''){
              NWF$('#' + jsCategory).style.visibility = "hidden";

           }
          }  

     });  
});

推荐答案

对此进行测试:

select:empty {
    display: none;
}

Invisible: ||<select></select>--<br>
Visible (whitespace): ||<select> </select>--<br>
Visible (children): ||<select><option>Options!</option></select>--

我不知道什么是 NWF $ ,但是如果您想通过javascript隐藏元素,则:

I do not know what is NWF$ but if you want hide an element by javascript:

TheElement.style.display = "none";

这篇关于Javascript-如何隐藏下拉菜单控件(如果为空)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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