jQuery实现radio第一次点击选中第二次点击取消功能

由于项目的需求,要求radio点击两次后为取消状态,不方便修改为checkbox,可以用正面的方法实现。

// jquery
  $('input:radio').click(function(){
    //alert(this.checked);
    //
    var $radio = $(this);
    // if this was previously checked
    if ($radio.data('waschecked') == true){
      $radio.prop('checked', false);
      $radio.data('waschecked', false);
    } else {
      $radio.prop('checked', true);
      $radio.data('waschecked', true);
    }
  });

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持我们!

(0)

相关推荐

  • JQuery判断radio(单选框)是否选中和获取选中值方法总结

    一.利用获取选中值判断选中 直接上代码,别忘记引用JQuery包 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <

  • 如何使用Jquery获取Form表单中被选中的radio值

    Jquery提供的选择器极大的方便了开发人员对Dom的操作,真正实现了代码简化,却功能强大的目标.下面就日常最常用的,在Form表单中如何获取被中选的Radio值做一小小的示例. form表单如下: 复制代码 代码如下: <form name='form1' action="#" method="post"> 此处略去200字 <input type="radio" name="opType" value=&

  • Jquery选中或取消radio示例

    JQuery获取选中的radio $('input:radio[name="sex"]:checked') Jquery选中或取消radio $("#tradeType0").attr("checked","checked"); $("#tradeType1").attr("checked",false);

  • JQuery判断radio是否选中并获取选中值的示例代码

    其他对radio操作功能,以后在添加.直接上代码,别忘记引用JQuery包 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head&

  • jquery判断单选按钮radio是否选中的方法

    本文实例讲述了jquery判断单选按钮radio是否选中的方法.分享给大家供大家参考.具体如下: html代码如下: <input type="radio" id="d1" name="ra" value="a" checked="checked" /> <input type="radio" id="d2" name="ra"

  • jquery checkbox,radio是否选中的判断代码

    1:判断radio 复制代码 代码如下: var selected = $('input[name=selectid:checked]').val();//若未被选中 则val() = null if(selected == null){ alert("未选中!"); }else{ alert("选中!"); } 2:判断checkbox 复制代码 代码如下: var n = $("input:checked").length; if(n==0)

  • JQuery控制radio选中和不选中方法总结

    一.设置选中方法 复制代码 代码如下: $("input[name='名字']").get(0).checked=true; $("input[name='名字']").attr('checked','true'); $("input[name='名字']:eq(0)").attr("checked",'checked'); $("input[name='radio_name'][checked]").va

  • Jquery 改变radio/checkbox选中状态,获取选中的值(示例代码)

    //如果之前有选中的,则把选中radio取消掉$("#tj_cat .pro_category").each(function(){ if ($(this).attr('checked')){                        $(this).attr('checked' ,false);                    }});//获取被选中的标签的值radio:(checkbox和这个一样) var val=$('input:radio[name="se

  • asp.net使用jQuery获取RadioButtonList成员选中内容和值示例

    复制代码 代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Web.Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o

  • jquery判断RadioButtonList和RadioButton中是否有选中项示例

    复制代码 代码如下: <pre class="html" name="code"> <%--Body 代码--%> <div> <asp:RadioButtonList ID="RadioButtonList1" runat="server"> <asp:ListItem Value="A">a</asp:ListItem> <a

随机推荐