如何清除Javascript中的单选按钮? [英] How to clear radio button in Javascript?

查看:105
本文介绍了如何清除Javascript中的单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为选择的单选按钮,选项是yes和no。如果我选择任何一个选项并单击标记为清除的按钮,则需要使用javascript清除选定的选项。如何才能做到这一点?

解决方案

您不需要具有唯一的 id 为元素,您可以通过它们的 name 属性访问它们:



如果您使用 name =选择,然后:


  • 很简单:

     
    $('input [name = Choose]')。attr('checked',false);


  • 或在纯JavaScript中:

     
    var ele = document.getElementsByName(Choose);
    for(var i = 0; i< ele.length; i ++)
    ele [i] .checked = false;

    JavaScript演示 a>



I have a radio button named "Choose" with the options yes and no. If I select any one of the options and click the button labeled "clear", I need to clear the selected option, using javascript. How can I accomplish that?

解决方案

You don't need to have unique id for the elements, you can access them by their name attribute:

If you're using name="Choose", then:

这篇关于如何清除Javascript中的单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆