码迷,mamicode.com
首页 > Web开发 > 详细

jquery 单选框整个选中

时间:2016-07-01 11:51:19      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

问题:遇到单选框,如图技术分享

解决办法:利用jqurey click->checked

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
<body>
<span class="pay-item" >
                <input type="radio" name="pay-item" class="big-radio" /><{$payment.app_display_name}>
</span>
<span class="pay-item" >
                <input type="radio" name="pay-item" class="big-radio" /><{$payment.app_display_name}>
</span>
</body>
</html>



<script>
    $(.pay-item).bind(click,function(e){
        $(this).find(input[name=pay-item])[0].checked = true;
    });

</script>

 代码解析:其中pay-item 为span标签的class值,和id(‘#pay-item’)不一样

input[name=pay-item] 为单选框的name;
 $(‘.pay-item‘).bind(‘click‘,function(e){
 $(this).find(‘input[name=pay-item]‘)[0].checked = true;
}

遇到在handlebar上的写法

$(‘body‘).on(‘click‘, ‘.pay-item‘, function(e){
    $(this).find(‘input[name=pay-item]‘)[0].checked = true;
})

 

jquery 单选框整个选中

标签:

原文地址:http://www.cnblogs.com/lemonphp/p/5632458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!