单击文本输入时清除单选按钮

nic*_*ick 1 html javascript forms jquery radio

我有一组4个单选按钮,后跟文本输入,当用户点击文本输入字段时,我试图清除所有无线电输入.到目前为止,这是我的代码.

 <input type="radio" name="radio"><label for="radio1">1</label>
 <input type="radio" name="radio"><label for="radio2">2</label>
 <input type="radio" name="radio"><label for="radio3">3</label>
 <input type="radio" name="radio"><label for="radio4">4</label>
 <input type="text" id="textInput">

 <script>
      $('#textinput').click(function () {
          radio.checked = false;
      });
 </script>
Run Code Online (Sandbox Code Playgroud)

Sat*_*pal 5

您可以使用.prop()来设置输入rabio按钮的已检查属性.textInput事件绑定时你也拼错了

<script>
      $('#textInput').click(function () {
          $('input[name="radio"]').prop("checked", false);
      });
 </script>
Run Code Online (Sandbox Code Playgroud)

DEMO