如何隐藏特定的文本字段对应于特定的onclick单选按钮?

时间:2017-06-12 05:44:13

标签: html5 bootstrap-modal

                                             个人          公司                           
                  
                                            
        活性         
                                               
        
                 

2 个答案:

答案 0 :(得分:0)

它是一个简单的禁用过程,您可以根据您的要求更改它

<ul>
   <li>
      <span>
           <input type="text" name="input_1" id="input_1"/>
      </span>
      <span>
           <button onclick="hide(1)">Hide</button>
      </span>
   </li>
   <li>
   <span>
       <input type="text" name="input_2" id="input_2"/>
   </span>
   <span>
        <button onclick="hide(2)">Hide</button>
   </span>
  </li>
  <li>
     <span>
       <input type="text" name="input_3" id="input_3"/>
    </span>
   <span>
      <button onclick="hide(3)">Hide</button>
   </span>
 </li>
  </ul>

java脚本:

   function  hide(index){
        $("#input_"+index).attr("disabled","disabled");
   }

答案 1 :(得分:0)

以下代码可能会对您有所帮助。

&#13;
&#13;
function hideAndShow(id)
{
  $('.showInit').show();
  $('#showOnClick'+id).hide();
}
&#13;
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="container">
  <div class="radio">
    <label><input type="radio" name="optradio" onclick="hideAndShow(1)">Option 1</label>
  </div>
  <div class="radio">
    <label><input type="radio" name="optradio" onclick="hideAndShow(2)">Option 2</label>
  </div>
  <div class="radio">
    <label><input type="radio" name="optradio" onclick="hideAndShow(3)">Option 3</label>
  </div>
  <input type="text" class="showInit" id="showOnClick1" placeholder="Text Box 1">
  <input type="text" class="showInit" id="showOnClick2" placeholder="Text Box 2">
  <input type="text" class="showInit" id="showOnClick3" placeholder="Text Box 3">
</div>
&#13;
&#13;
&#13;