Coffeescript 咖啡脚本更改时未显示Div

Coffeescript 咖啡脚本更改时未显示Div,coffeescript,Coffeescript,我想在表单中隐藏一个选项,除非选择了一个特定的选项,但我的咖啡脚本似乎不起作用。它看起来像: jQuery -> $('.input.boolean.optional').hide() selected = $('#stand_type :selected').text() value = "Microphone" $('#stand_type').change -> $('.input.boolean.optional').show() if selec

我想在表单中隐藏一个选项,除非选择了一个特定的选项,但我的咖啡脚本似乎不起作用。它看起来像:

jQuery ->
  $('.input.boolean.optional').hide()
  selected = $('#stand_type :selected').text()
  value = "Microphone"
  $('#stand_type').change ->
      $('.input.boolean.optional').show() if selected is value

这段代码编译正确。是的,我知道ID和类选择器,它们在代码中是不同的,因为我使用的是simple_form,它只提供一个div a类。这就是为什么隐藏它时我使用的是类而不是ID。脚本中的逻辑是错误的。在更新值之前检查该值,使其始终为空。脚本应如下所示:

jQuery ->
  $('.input.boolean.optional').hide()
  value = "Microphone"
  $('#stand_type').change ->
    selected = $('#stand_type :selected').text()
    $('.input.boolean.optional').show() if selected is value

脚本中的逻辑是错误的。在更新值之前检查该值,使其始终为空。脚本应如下所示:

jQuery ->
  $('.input.boolean.optional').hide()
  value = "Microphone"
  $('#stand_type').change ->
    selected = $('#stand_type :selected').text()
    $('.input.boolean.optional').show() if selected is value