仅针对某些选项,以“多重选择”为条件

我有一个多选功能,需要根据第一个选择中选择的选项显示/隐藏另一个选择。有3个选项应引起另一个选择的出现-所有其他选项不应引起任何更改。


如果单独选择这些选项,则可以正常工作。但是,如果选择了一个选项以及其他任何选项,则该选项将无效。


由于CMS约束,我无法将类添加到选项中。


这是我当前的jQuery代码。


$('#freeform_how_would_you_best_describe_your_companys_research_activity').change(function() {


            var selectedItems


            if ($(this).val() == 'Drug Discovery/Development' || $(this).val() == 'Therapeutics' || $(this).val() == 'Vaccines' ) {

                $('label[for="freeform_tell_us_more_about_your_research_activity"], select#freeform_tell_us_more_about_your_research_activity').slideDown();

            } else {

                $('label[for="freeform_tell_us_more_about_your_research_activity"], select#freeform_tell_us_more_about_your_research_activity').slideUp();

            }

        });


叮当猫咪
浏览 167回答 2
2回答

波斯汪

一些额外的谷歌搜索和实验,后来我找到了解决方案        $('#freeform_how_would_you_best_describe_your_companys_research_activity').change(function() {            var values = $(this).val();            console.log(values)            if(values.includes("Vaccines")|| values.includes("Therapeutics") || values.includes("Drug Discovery/Development")){                $('label[for="freeform_tell_us_more_about_your_research_activity"], select#freeform_tell_us_more_about_your_research_activity').slideDown();            } else {               $('label[for="freeform_tell_us_more_about_your_research_activity"], select#freeform_tell_us_more_about_your_research_activity').slideUp();            }        });
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript