Javascript 如果“上一个”为空,则清除“下一个嵌套的选择标记”

Javascript 如果“上一个”为空,则清除“下一个嵌套的选择标记”,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我有一个问题-我有几个相互依赖的嵌套select输入。我正试图产生以下效果-如果我选择“选择”选项,下面所有的选择标记都将被清除 HTML: <fieldset> <legend>Dwelling</legend> <p> <span>Continet:</span> <select class="dwelling" name="cont

我有一个问题-我有几个相互依赖的嵌套select输入。我正试图产生以下效果-如果我选择“选择”选项,下面所有的选择标记都将被清除

HTML:

<fieldset>
            <legend>Dwelling</legend>
            <p> 
                <span>Continet:</span> <select class="dwelling" name="continent" id="continent" onchange="getplaces(this.value,'country',this);"></select>
            </p>
            <p>
                <span>Country:</span> <select class="dwelling" name="country" id="country" onchange="getplaces(this.value,'province',this);"></select>
            </p>
            <p>
                <span>State / Provice:</span> <select class="dwelling" name="province" id="province" onchange="getplaces(this.value,'region',this);"></select>
            </p>
            <p>
                <span>County / Region:</span> <select class="dwelling" name="region" id="region" onchange="getplaces(this.value,'city',this);"></select>
            </p>
            <p>
                <span>City:</span> <select class="dwelling" name="city" id="city"></select>
            </p>
</fieldset>
编辑:
谢谢大家的快速回复,但也许我的问题表述错了。我只想清除带有“choose”(选择)选项的标签之后的next select(下一个选择)标签,这样所有标签都位于它之前,不会受到影响。

您需要针对next
p
元素中的所有
select
元素

function getplaces(val, src, t) {
    if (val != "choose") {
        //fetching dependent records + one option on top with "choose" value    
    } else {
        $(t).closest('p').nextAll().find('select.dwelling').empty();
    }
}

演示:

您需要针对下一个
p
元素中的所有
选择
元素

function getplaces(val, src, t) {
    if (val != "choose") {
        //fetching dependent records + one option on top with "choose" value    
    } else {
        $(t).closest('p').nextAll().find('select.dwelling').empty();
    }
}

演示:

我猜这正是您希望从下拉列表中删除的选项

$(t).closest('fieldset').find(".dwelling option").remove();

我猜这只是你想从下拉列表中删除的选项

$(t).closest('fieldset').find(".dwelling option").remove();

为什么是nextall?它只选择同级,您选择的都是字段集的后代。为什么选择nextall?它只选择同级,您选择的是字段集的所有后代。