Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.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 Jquery Remove NextAll不处理选择_Javascript_Jquery_Html_Dom - Fatal编程技术网

Javascript Jquery Remove NextAll不处理选择

Javascript Jquery Remove NextAll不处理选择,javascript,jquery,html,dom,Javascript,Jquery,Html,Dom,这是我的问题 在StackOverflow上发现的相关/类似问题中找不到任何有效的解决方案 我有一个用ajax数据填充的select,我们称之为“mainSelect”,它有一个“selectSomething”类。 在事件(change/keyup)中,如果所选值不是“”,则它会自动在第一个值下添加一个“subChoice”select,该值也具有“selectSomething”类 当用户在第二次选择中选择某个内容时,它会在当前选择下添加(或不添加,取决于选择了哪个值)一个新选择(仍然具有s

这是我的问题

在StackOverflow上发现的相关/类似问题中找不到任何有效的解决方案

我有一个用ajax数据填充的select,我们称之为“mainSelect”,它有一个“selectSomething”类。 在事件(change/keyup)中,如果所选值不是“”,则它会自动在第一个值下添加一个“subChoice”select,该值也具有“selectSomething”类

当用户在第二次选择中选择某个内容时,它会在当前选择下添加(或不添加,取决于选择了哪个值)一个新选择(仍然具有selectSomething类)。等等像这样:

以下是html部分:

<div class='choiceDiv'>
    <select class='selectSomething' id='masterSelect'>
    </select>
</div>
不起作用了。。。有什么想法吗

谢谢你的阅读/帮助

编辑:

如果我在控制台中输出:

console.log($(this).nextAll('.selectSomething'));

我得到一个对象[],它的长度为0…

对于next,您不需要调用parent(),因为在这种情况下,您将在parent之后获得下一个元素

试试看:

$(this).nextAll('.selectSomething').remove();
使用

之后

因为在动态地从选择框中删除元素并向其添加选项之后,需要刷新它,您需要使用

$(this).nextAll('.selectSomething').remove();
而不是

$(this).parent().nextAll('.selectSomething').remove();
因为您需要获得最接近的父对象,然后在其中找到任何select并将其删除

说明:

你的代码


我会尝试,但我需要删除所有“following”。选择某个selects,而不是current(触发事件的那一个),我可能会得到5个具有选定值的following selects,然后我更改第三个的值。所以在那个时刻,选择4和5必须消失,并且在第三次选择更改时触发的事件将显示(或不显示)第四次选择。。。Idk如果我解释清楚与否…@Julo0sS:你可以简单地执行
$(this).nextAll('.selectSomething').remove()然后。让我知道这是否适合你。
$(this).parent().nextAll('.selectSomething').selectmenu('refresh', true);
$(this).parent().nextAll('.selectSomething').remove();
$(this).nextAll('.selectSomething').remove();
$(this).parent().nextAll('.selectSomething').remove();
$(this)         // this here is the selectSomething dropdown
    .parent()   // this is the choiceDiv parent div element
    .nextAll('.selectSomething')    // there nothing next to choiceDiv
    .remove();  // that's why this remove does not works here