javascript - 如何根据输入值跳过自定义垂直 slider 中的元素

标签 javascript jquery

我试图根据输入值跳过一些“skip”类的元素,但当选择输入值“否”时,它无法正常工作。

$("input:radio[name='q1']").change(function() {
  if ($(this).val() == 'Yes') {
    $('.skip').removeClass('hidden');
  } else {
    $('.skip').addClass('hidden');
  }
});

这是 fiddle 中的完整代码

最佳答案

在这里,我认为这就是您想要做的:

https://jsfiddle.net/jfojv01e/

问题是:

  1. 您使用 .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/

    相关文章:

    javascript - 如何格式化 2015 年 10 月 23 日星期五 12 :00:00 am to particular format datetime string?

    javascript - 如何在循环中将选项中的值保存到一个数组单元格

    javascript - JQuery 验证插件 : make input required depending on radio button value

    javascript - 如何获取DropDown中选中的数据ID?

    javascript - 从 AngularJS 中的 Controller 函数发送数据到 View

    javascript - 这个速记语句实际上是如何工作的? "x = ( typeof x != ' 未定义' && x 数组实例) ? x : [];"

    javascript - jQuery/Ajax - 成功消息后重定向到另一个页面

    javascript - 使用 CSS 循环颜色过渡

    jquery - 使用 AJAX/JQUERY 验证多个输入并更改输入的 css

    javascript 函数禁用和/或与 fancybox 冲突