如果不显示,则必须清除文本框

问题描述 投票:-4回答:1

我网站上的用户可以用不同的主题填写表格。如果他们填写其中一个主题,并且他们决定选择另一个他正在填写的主题。然后另一个打开。但是,当用户选择自己填写的同一主题之前,仍然要填写。我想要拥有的是,当用户决定选择另一主题时,旧主题隐藏并清除其中的所有信息。我的代码是这样的,但是非常简化:

<div class="steps">
<label for="example">Example</label>
<input type="text" name="inputexample" id="inputexample" />
</div>

而且,这是fiddle

html jquery input hide
1个回答
0
投票
$('input[type=radio]').on('change', function(){
    var class1=$(this).attr('class');
    $('div').each(function(){
      $('input[type=text]').val('');
      if($(this).attr('id')==class1)
      {
          $(this).show();
      }
      else{
         $(this).hide();
        }
    }); 
});

演示:

http://jsfiddle.net/uPHSr/1/

© www.soinside.com 2019 - 2024. All rights reserved.