Javascript 选择单选按钮codeigniter时显示或隐藏字段

Javascript 选择单选按钮codeigniter时显示或隐藏字段,javascript,php,codeigniter,Javascript,Php,Codeigniter,我目前正在做一个项目。我有两个单选按钮,一个单程,两个往返。当用户尝试选择单向单选按钮时,返回文本字段将隐藏 我看到一条帖子,有人对这个问题发表了评论。场景:我选择了单向单选按钮,返回字段将消失,是的,它正在工作,但有一些问题。如果我改变主意,从单程单选按钮改为往返按钮怎么办?问题是返回字段没有返回 **看法** //我的单选按钮 <div class="pure-u-1-1 radiobtn"> <form action=""> <

我目前正在做一个项目。我有两个单选按钮,一个单程,两个往返。当用户尝试选择单向单选按钮时,返回文本字段将隐藏

我看到一条帖子,有人对这个问题发表了评论。场景:我选择了单向单选按钮,返回字段将消失,是的,它正在工作,但有一些问题。如果我改变主意,从单程单选按钮改为往返按钮怎么办?问题是返回字段没有返回

**看法**

//我的单选按钮

<div class="pure-u-1-1 radiobtn">
     <form action="">
           <input type="radio" name="flight_type"  value="one_way" class="onew" style=""  >One Way
           <input type="radio" name="flight_type" class="roundw" style="" checked>Round Trip
     </form>
</div>
//将隐藏/显示的返回字段

<div class="pure-u-1-1 dr" id="try">
      <label for="return" class="drr">Return</label>
      <input type="text" id="return" name="return" class="departreturn"><br>

</div>
JS

只需使用。切换

.切换 描述:显示或隐藏匹配的元素

在没有参数的情况下,.toggle方法仅切换元素的可见性:

参考:

单行线 往返 回来 $document.on'change',输入:radio[name=航班类型]',函数{ $'div[id^=try]'。toggle;//切换从my_radio开始的所有div_ $+$this.attr'id'+'\u text.show;//显示当前的 };
您好,先生,我有一个问题,我可以做些什么来防止在我选择一次行程时验证是否需要显示返回字段?
<script type="text/javascript">
$(document).on('change', 'input:radio[name=flight_type]', function(){
    $('div[id^="try"]').hide(); // hide all DIVs begining with "my_radio_"
    $('#' + $(this).attr('id') + '_text').show(); // show the current one
});

</script>