Jquery点击功能似乎只工作一次



我正试图根据按钮单击页面上方的按钮预先选择一个单选按钮。下面的代码确实可以工作,但它似乎只正确选择了一次单选选项。

jQuery(document).ready(function(){
jQuery(".select-one").on('click', function(){
jQuery("input[type='radio'][id='choice_25_25_0']").attr("checked", true);
});
jQuery(".select-two").on('click', function(){
jQuery("input[type='radio'][id='choice_25_25_1']").attr("checked", true);
});
jQuery(".select-three").on('click', function(){
jQuery("input[type='radio'][id='choice_25_25_2']").attr("checked", true);
});
});

有什么我可以添加到这个代码,使它运行每次点击按钮?如有任何帮助,不胜感激。

JFiddle例子

.attr()改为.prop()

jQuery(document).ready(function(){
jQuery(".select-one").on('click', function(){
jQuery("input[type='radio'][id='choice_25_25_0']").prop("checked", true);
});
jQuery(".select-two").on('click', function(){
jQuery("input[type='radio'][id='choice_25_25_1']").prop("checked", true);
});
jQuery(".select-three").on('click', function(){
jQuery("input[type='radio'][id='choice_25_25_2']").prop("checked", true);
});
});

最新更新