简体   繁体   English

如何显示与他人一起选择的隐藏DIV?

[英]How can I show a hidden DIV for a selection included with others?

I have a javascript file that when called, checks to see if a particular option is selected on a form. 我有一个JavaScript文件,该JavaScript文件在调用时检查是否在表单上选择了特定选项。 The form allows for multiple selections before being submitted. 该表格允许在提交之前进行多项选择。 When a particular item is selected within the given choices it shows a hidden menu. 在给定的选项中选择了特定项目时,它将显示一个隐藏菜单。 In this case with "audits" I am able to show the hidden menu fine when just "audits" is selected from the list. 在这种情况下,如果使用“审核”,则仅从列表中选择“审核”时,我就能很好地显示隐藏菜单。 However, I'm having much difficulty in figuring out how to get the menu to show when "audits" would be selected/highlighted with others. 但是,在弄清楚如何使菜单与其他人一起选择/突出显示“审计”时,我遇到了很多困难。 Eg: I had audits, services, someotheroption Below you can see the code I'm currently using and that's working only when the single item is selected. 例如:我有审核,服务,其他选项下面您可以看到我当前正在使用的代码,并且只有在选择单个项目时该代码才起作用。 Any guidance would be much appreciated. 任何指导将不胜感激。

function toggleFields(){
    function toggleFields(){
        if ($("#installations").val() == "audits"){
            $("#dbcredentialsfield").show();
        }
        else
            $("#dbcredentialsfield").hide();
}

Using the code you have so far, I assume you probably want something like this: 使用到目前为止的代码,我假设您可能想要这样的东西:

$('#installations').on('change', function(){
   $("#dbcredentialsfield").toggle($(this).val() == 'audits');
});

This says; 这样说; when the select element (assuming your dropdown has the id of installations ) changes, toggle the visibility of the element with id dbcredentialsfield depending on if the value of the select is audits or not. 当选择元件(假设你的下拉列表具有的ID installations )的变化,切换元素的可见性与ID dbcredentialsfield取决于如果选择的值audits与否。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM