2017-10-28 18 views
2

HTML有効: をここで私はjqueryのラジオボタンや入力ラジオボタンや入力

<div class="form-check form-check-inline"> 
    <label class="form-check-label"> 
     <input class="form-check-input" type="radio" name="inlineRadioOptions" id="yucho" value="Yucho"> ゆうちょ 
    </label> 
</div> 
<div class="form-check form-check-inline"> 
    <label class="form-check-label"> 
     <input class="form-check-input" type="radio" name="inlineRadioOptions" id="UFJ" value="UFJ"> UFJ 
    </label> 
</div> 
<div class="form-check form-check-inline"> 
    <label class="form-check-label"> 
     <input class="form-check-input" type="radio" name="inlineRadioOptions" id="Mizuho" value="Mizuho"> みずほ 
    </label> 
</div> 
<div class="form-check form-check-inline"> 
    <div class="input-group"> 
     <label class="form-check-label"> 
      <input class="form-check-input" type="radio" name="inlineRadioOptions" id="Other" value="Other">Other 
     </label> 
    <input type="text" class="form-control" id="unique" aria-label="Text input with radio button" disabled> 
    <div class="btn-group" role="group" aria-label="Basic example"> 
     <button type="button" class="btn btn-success">Add</button> 
     <button type="button" class="btn btn-success">Remove</button> 
    </div> 
</div> 

を持っている:入力を有効にする:私は、ラジオボタンが機能を持っていたいです他の半径ボタンをクリックするとクリックされ、無効になります

<script> 
    $(document).ready(function() { 
     $("#Other").click(function() { 
      $("#unique").prop("disabled", false); 
     }); 
    }); 
</script> 

変更が必要ですか?あなたはcheckboxないradio

​​

を使用する必要が

+0

どこに他のラジオボタンがありますか? –

答えて

2

私はあなたがクリックした繰り返しを避けるために、ラジオボタンを無効にしたいと思います。

$(document).ready(function() { 
 
\t \t 
 
    var allOptions = $('input[name=inlineRadioOptions]') 
 
    allOptions.click(function() { 
 
    
 
     $("#unique").prop("disabled", false); 
 
     allOptions.prop('disabled', true); 
 
     
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 

 
<label class="form-check-label"> 
 
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="Other" value="Other">Other 
 
</label> 
 
<label class="form-check-label"> 
 
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="Other2" value="Other2">Other2 
 
</label> 
 
<input type="text" class="form-control" id="unique" aria-label="Text input with radio button" disabled>

+0

コードは素晴らしいですが、私の場合はどのように動作しませんでした。私はあなたのコードを別のHTMLに入れて実行しますが、うまくいきませんでした –

+0

複数のオプションを持つラジオボタンですか?コードを表示できますか? –

+0

私はすでに完全なコードブロックで質問を編集しましたが、あなたはそれを確認できますか? –

0

は、次にスクリプトがある -

$(document).ready(function() { 
    $("#Other").click(function() { 
     if($(this).prop('checked') == true){ 
      $("#unique").prop("disabled", true); 
     } else { 
      $("#unique").prop("disabled", false); 
     } 
    }); 
}); 
関連する問題