jQuery / coffeescript:隐藏除选定输入div之外的所有内容

时间:2014-03-28 01:34:06

标签: jquery ruby-on-rails coffeescript

我有一个输入复选框,在下面的html的最后一行中定义。我正在使用jQuery / Coffeescript尝试使用类" control-group ..."隐藏页面上的所有其他div。选中输入框时。问题是,我想保留这个特殊的div,但是还没有。相反,他们都消失了。我使用了" not()"方法和许多jQuery选择器在代码中以不同的方式没有成功。你能帮我吗?谢谢!

HTML

<div class="control-group boolean optional question_answers_correct_answer">
  <label class="boolean optional control-label" for="question_answers_attributes_0_correct_answer">Correct answer</label>
    <div  class="controls"><input name="question[answers_attributes][0][correct_answer]" value="0" type="hidden">
      <label class="checkbox">
        <input class="boolean optional" id="question_answers_attributes_0_correct_answer" name="question[answers_attributes][0][correct_answer]" value="1" type="checkbox">

的CoffeeScript

jQuery ->
  $('input[name*="correct_answer"]').on "change", (event) ->
    $("div.control-group.boolean.optional.question_answers_correct_answer").hide(300)

2 个答案:

答案 0 :(得分:0)

尝试使用:

$("div.control-group").hide(300)
$(".boolean.optional.question_answers_correct_answer").show()

或:

$("div.control-group").not(".boolean.optional.question_answers_correct_answer").hide(300)

答案 1 :(得分:0)

如果($( “div.control基团”)。hasClass( 'boolean.optional.question_answers_correct_answer'))     $( “div.control组”)。节目() 其他     $( “div.control群”)隐藏(300);