Javascript 根据单选按钮显示/隐藏文本文件';选择

Javascript 根据单选按钮显示/隐藏文本文件';选择,javascript,jquery,ruby-on-rails-3,Javascript,Jquery,Ruby On Rails 3,我知道这是一个重复的问题,但我不能让它运行。我尝试了我在SO和Google找到的所有解决方案 我的页面中有这个单选按钮表单。我想要的是,当用户选择“仅一名与会者”选项时,只会为该选项显示一个文本字段。如果用户选择另一个,它将消失 用户仅选择一个选项后,将显示文本框 我一直在尝试使用javascript。我使用这段代码 <script> $(document).ready(function() $("#send_to_one").hide

我知道这是一个重复的问题,但我不能让它运行。我尝试了我在SO和Google找到的所有解决方案

我的页面中有这个单选按钮表单。我想要的是,当用户选择“仅一名与会者”选项时,只会为该选项显示一个文本字段。如果用户选择另一个,它将消失

用户仅选择一个选项后,将显示文本框

我一直在尝试使用javascript。我使用这段代码

<script>
    $(document).ready(function()
        $("#send_to_one").hide();
        $("input:radio[name="people"]").change(function(){  
          if(this.checked){
            if(this.value =='one'){
              $("#send_to_one").show()
            }else{
              $("#send_to_one").hide();
            }
         }
    }
  });
</script>

$(文档).ready(函数()
$(“#将#发送到#one”).hide();
$(“输入:radio[name=“people”]”)。更改(函数(){
如果(选中此项){
如果(this.value='one'){
$(“发送给某人”).show()
}否则{
$(“#将#发送到#one”).hide();
}
}
}
});
表单的代码是

  <div id="send_to">
    <input type="radio" id="send_poll" name="people" value="all" checked="checked">all the attendees</br>      
    <input type="radio" id="send_poll" name="people" value="one" >only one attendee<br/>
    <div id="send_to_one">
      <label>Write the attendee's name: </label><input type="text" id="attendeename"><br/><br/>
    </div>
    <input type="radio" id="send_poll" name="people" value="group">a group of attendees</br>              
  </div>    

所有与会者
只有一名与会者
写下与会者的姓名:

一群与会者
我已经检查了javascript文件是否已加载。我还尝试将javascript代码放在html.erb文件中表单所在的位置,放在一个单独的.js文件和application.htm.erb的
部分中,但没有成功。为了工作,我需要将代码的每一部分放在哪里?

使用Rails 3.0.4、Ruby 1.8.9。我还使用了JQuery

$(document).ready(function() {
    $("#send_to_one").hide();
    $("input:radio[name='people']").change(function(){  
         if(this.checked){
            if(this.value =='one'){
              $("#send_to_one").show()
            }else{
              $("#send_to_one").hide();
            }
         } 
    });
});
您的代码是正确的,但是缺少了一些大括号、方括号和未替换的引号。您是否使用任何形式的智能javascript编辑器?因为您确实应该

HTML:


(OT)

!=

!=
从我的头顶掠过:
$(
应该是
$(
<div id="send_to">
  <input type="radio" id="send_poll" name="people" value="all" checked="checked" />all the attendees<br/>      
  <input type="radio" id="send_poll" name="people" value="one" />only one attendee<br/>
  <div id="send_to_one">
      <label>Write the attendee's name: </label><input type="text" id="attendeename" /><br/><br/>
  </div>
  <input type="radio" id="send_poll" name="people" value="group" />a group of attendees<br/>              
</div>
$(document).ready(function(){

    $("#send_to_one").hide();

    $("input:radio[name='people']").change(function(){  

            if(this.value == 'one' && this.checked){
              $("#send_to_one").show();
            }else{
              $("#send_to_one").hide();
            }

    });

});