zoukankan      html  css  js  c++  java
  • 点击文字选中radio

    <html>
    <body>
    <form action="" name="form1" method="post">


    <br />
    <label style="cursor:pointer" for="man">
    <input type="radio" value="http://fanjf.iteye.com/blog/男" name="man" id="man"/>男
    </label>
    <label style="cursor:pointer" for="man2">
    <input type="radio" value="http://fanjf.iteye.com/blog/女" name="man" id="man2"/>女
    </label>
    </form>

    <input type="radio" id="male" name="sex" checked="checked"/><label style="cursor:pointer" for="male">男1</label>

    <input type="radio" id="female" name="sex" /><label style="cursor:pointer" for="female">女1</label>

    </body>
    </html>

    有ID的可以用以上方法,如果没有id呢,那只能自己写js了,一下方法仅供参考

    $(".isplist").click(function(){
    //alert($(this).val());
    $(this).find("input[type=radio]").attr("checked", 'checked');
    });

    <div name="isp" class="isplist"><input type="radio" name="ispname" value="1"> 联通 </div>
    <div name="isp" class="isplist"><input type="radio" name="ispname" value="2"> 电信 </div>
    <div name="isp" class="isplist"><input type="radio" name="ispname" value="3"> 移动 </div>
    <div name="isp" class="isplist"><input type="radio" name="ispname" value="4"> 铁通 </div>
    <div name="isp" class="isplist"><input type="radio" name="ispname" value="5"> 长城 </div>
    <div name="isp" class="isplist"><input type="radio" name="ispname" value="6"> 广电 </div>
    <div name="isp" class="isplist"><input type="radio" name="ispname" value="7"> 教育网 </div>
    <div name="isp" class="isplist"><input type="radio" name="ispname" value="8"> 其它 </div>

     window.onload = function () {
    //点击radio后面的文本选中radio
    //    labels = document.getElementById('scalul').getElementsByTagName('span');
    //    for (i = 0, j = labels.length; i < j; i++) {
    //        labels[i].onclick = function () {
    //            var vastr = $(this).parents("li").find("input").val();
    //            $(this).parents("li").find("input[type=radio][value=" + vastr + "]").attr("checked", 'checked');
    //        }
    //    }
    //点击整个li选中其里面的radio
        labelsa = $(".scalul .li").find("li");
        for (i = 0, j = labelsa.length; i < j; i++) {
            labelsa[i].onclick = function () {
               var vastra = $(this).find("input").val();
                $(this).parents("li").find("input[type=radio][value=" + vastra + "]").attr("checked", 'checked');
            }
        }

    }

  • 相关阅读:
    vue实现短信验证码登录
    使用vue3.0和element实现后台管理模板
    vue导出excel数据表格功能
    Vue2.0-token权限处理
    vue2.0实现购物车功能
    Vue图片懒加载之lazyload插件使用
    H5 canvas 绘图
    前端常见跨域请求 方法
    Html5 @media + css3 媒体查询
    Java面试之RabbitMQ
  • 原文地址:https://www.cnblogs.com/kingreatwill/p/4211501.html
Copyright © 2011-2022 走看看