Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果没有结果,如何隐藏下拉列表_Javascript_Jquery_Jquery Chosen - Fatal编程技术网

Javascript 如果没有结果,如何隐藏下拉列表

Javascript 如果没有结果,如何隐藏下拉列表,javascript,jquery,jquery-chosen,Javascript,Jquery,Jquery Chosen,我正在制作一个内置诀窍的页面。 我正在筛选下拉列表,如果该下拉列表没有结果,我想隐藏它们 以下是网页: 这是有人给我在Knack论坛上使用的脚本,但我不知道如何实现。我是javascript新手,所以任何帮助都会很棒!谢谢 $("#parentDropDownID").chosen().change(function () { var CheckOptions = $("#ChildDropDownID").find("option"); if (CheckOptions.le

我正在制作一个内置诀窍的页面。 我正在筛选下拉列表,如果该下拉列表没有结果,我想隐藏它们

以下是网页:

这是有人给我在Knack论坛上使用的脚本,但我不知道如何实现。我是javascript新手,所以任何帮助都会很棒!谢谢

$("#parentDropDownID").chosen().change(function () {
    var CheckOptions = $("#ChildDropDownID").find("option");
    if (CheckOptions.length == 0) {
        $("#ChildDropDownID").parent().parent().hide();
    }
    else {
        $("#ChildDropDownID").parent().parent().show();
    }
});
这是我用不同id试过的。我试过几种不同的方法

$(document).on('knack-scene-render.scene_79', function (event, view, data) {
$("#connection-picker-chosen-field_380").chosen().change(function () {
var CheckOptions = $("#view_371_field_380_chzn").find("option");
if (CheckOptions.length == 1) {
$("#view_371_field_380_chzn").parent().parent().hide();
}

else
{
$("#view_371_field_380_chzn").parent().parent().show();
}
});
});
以下是包含其中一个下拉列表的整个DIV:

这是一个下拉列表,其中包含1个结果。我需要这一个被显示,上面的一个被隐藏

<div class="kn-input kn-input-connection control" id="kn-input-field_374" data-input-id="field_374" david_debug_id="0" data-is-connection="true">
<label for="field_374" class="label kn-label"><span>Cable Add-Ons</span></label>
<div class="control">
<input class="connection" name="field_374" type="hidden" value="%22%22">
<input name="object_key" type="hidden" value="object_25">
<input name="object_name" type="hidden" value="Cable Add-Ons">

<div id="connection-picker-chosen-field_374" style="">
<select id="view_371-field_374" name="field_374" class="chzn-select select chzn-done" data-placeholder="" style="display: none;"><option value="">Select</option><option value="5b228005af12f63c56567b12">Digital TV Service - $15.05</option></select><div id="view_371_field_374_chzn" class="chzn-container chzn-container-single" style="width: 350px;" title=""><a href="javascript:void(0)" class="chzn-single" tabindex="-1"><span>Select</span><div><b></b></div></a><div class="chzn-drop" style="left: -9000px; width: 350px; top: 0px;"><div class="chzn-search"><input type="text" autocomplete="off" style="width: 342px;"></div><ul class="chzn-results"><li id="view_371_field_374_chzn_o_0" class="active-result result-selected" style="">Select</li><li id="view_371_field_374_chzn_o_1" class="active-result" style="">Digital TV Service - $15.05</li></ul></div></div>
</div>

</div>

<p class="kn-instructions" style="display: none;"></p>
</div>

让它工作起来。我不得不删除第二行代码。
谢谢

我尝试了下列方法,但没有成功。我还尝试了许多不同的变体。在其中一个下拉列表的HTML块中添加。例如,您可以看到我尝试过的代码以及HTML。谢谢
<div class="kn-input kn-input-connection control" id="kn-input-field_374" data-input-id="field_374" david_debug_id="0" data-is-connection="true">
<label for="field_374" class="label kn-label"><span>Cable Add-Ons</span></label>
<div class="control">
<input class="connection" name="field_374" type="hidden" value="%22%22">
<input name="object_key" type="hidden" value="object_25">
<input name="object_name" type="hidden" value="Cable Add-Ons">

<div id="connection-picker-chosen-field_374" style="">
<select id="view_371-field_374" name="field_374" class="chzn-select select chzn-done" data-placeholder="" style="display: none;"><option value="">Select</option><option value="5b228005af12f63c56567b12">Digital TV Service - $15.05</option></select><div id="view_371_field_374_chzn" class="chzn-container chzn-container-single" style="width: 350px;" title=""><a href="javascript:void(0)" class="chzn-single" tabindex="-1"><span>Select</span><div><b></b></div></a><div class="chzn-drop" style="left: -9000px; width: 350px; top: 0px;"><div class="chzn-search"><input type="text" autocomplete="off" style="width: 342px;"></div><ul class="chzn-results"><li id="view_371_field_374_chzn_o_0" class="active-result result-selected" style="">Select</li><li id="view_371_field_374_chzn_o_1" class="active-result" style="">Digital TV Service - $15.05</li></ul></div></div>
</div>

</div>

<p class="kn-instructions" style="display: none;"></p>
</div>