首页 > 解决方案 > 加载时的jQuery检测选择了哪个单选按钮

问题描述

工作示例:https ://codepen.io/stevland/pen/arOEEQ 。

我正在使用 jQuery 根据打开/关闭哪个单选按钮来更改相应表格的不透明度。

$('input:radio').click(function() {
    $("input:radio").each(function() {
        $(this).closest("table").toggleClass("highlight", $(this).is(":checked"));
    });
});

除了一个警告外,它运行良好:访问页面时,必须单击单选按钮才能启动该功能。

我想根据已选中的单选按钮扩展代码以在页面加载后立即工作:

<input type="radio" checked />

标签: jqueryradio-button

解决方案


推荐阅读