包装的输入radio上的Jquery事件覆盖“checked”事件 [英] Jquery event on wrapped input radio override 'checked' event

查看:183
本文介绍了包装的输入radio上的Jquery事件覆盖“checked”事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在点击td但保留默认输入事件时选中并取消选中(切换)收音机。

I want to check and uncheck (toggle) the radio when "td" is click but preserving the default input event

<table>
   <tr>
      <td>
          <input type='radio'>
      </td>
   </tr>
</table>

我的代码尝试次数:


http://jsfiddle.net/UJXRu/

尝试2:
http://jsfiddle.net/UJXRu/1/

尝试3:
http ://jsfiddle.net/UJXRu/2/

预览:

$("td").click(function(e) {
    if (!$(e.target).is("input")) {
        var bool = !$(this).children("input").is(':checked');
        $(this).children("input").attr("checked", bool)
    }
    else{
        var bool2 = !$(e.target).is(':checked');
        $(e.target).attr('checked',bool2);
    }
});


推荐答案


$ b

Try this out..

$("td").click(function(e) {
    if (e.target.type !== 'radio') {
        $(this).find(":radio").trigger('click');
    }
});

jsfiddle

如果你想使td和单选按钮切换收音机选中的属性,你可以这样做:

If you want to make the td and radio button toggle the radio checked property you could do something like this:

$("td").toggle(function() {
    $(this).children(":radio").attr("checked", true);
}, function() {
    $(this).children(":radio").attr("checked", false);
});

jsfiddle

这篇关于包装的输入radio上的Jquery事件覆盖“checked”事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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