radio中最佳解决方案

radio中最佳解决方案

1、html中

              <td>
                      <input id="status" name="status" type="radio" value="1" checked="checked" onclick="qy()"/>
                      <span>启用</span>
                      <input id="status" name="status" type="radio" value="0"  onclick="jy()"/>
                       <span>禁用</span>
               </td>

2、js中

    function qy(){
        $("input[name='status']").eq(0).attr("checked","checked");
        $("input[name='status']").eq(1).removeAttr("checked");
        $('input[name="status"]:eq(0)').attr("value", 1);
        return;
    };
    function jy(){
        $("input[name='status']").eq(0).removeAttr("checked");
        $("input[name='status']").eq(1).attr("checked","checked");
        $('input[name="status"]:eq(1)').attr("value", 0);
        return;
    };
原文地址:https://www.cnblogs.com/vimx86/p/6919368.html