我试图根据输入值跳过一些“skip”类的元素,但当选择输入值“否”时,它无法正常工作。
$("input:radio[name='q1']").change(function() {
if ($(this).val() == 'Yes') {
$('.skip').removeClass('hidden');
} else {
$('.skip').addClass('hidden');
}
});
这是 fiddle 中的完整代码
最佳答案
在这里,我认为这就是您想要做的:
https://jsfiddle.net/jfojv01e/
问题是:
- 您使用
.next()
只能给出直接兄弟
,因此请使用.nextAll
Given a jQuery object that represents a set of DOM elements, the .next() method allows us to search through the immediately following sibling of these elements in the DOM tree and construct a new jQuery object from the matching elements
- 您的条件是反义词,应该是
$(this).val() == 'No'
- 您没有跳过隐藏元素,因此它仍在查找它们...请参阅我添加的
:not
选择器$currentItem.nextAll('.scrollStep:not(.hidden)' )
关于javascript - 如何根据输入值跳过自定义垂直 slider 中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40766195/