我有一个输出许多 div 的 php 脚本,在每个 div 中都有一个具有特定值的单选按钮。我想通过在单击 div 时选择单选按钮来创建更好的用户体验,这在我使用 jquery 时不是什么大问题。问题是,当单击单选按钮本身而不是 div 时,以下单击不再具有选择单选按钮的效果。我还尝试在检查选定的单选按钮之前删除每个单选按钮上的选中属性,但这不起作用。这是我的做法:
$(".fontCellDiv").click(function(){
$(this).find("input").attr("checked", true);
});
有人有想法吗?
最佳答案
来自文档:
Attributes vs. Properties
The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.
关于javascript jquery 选择单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26053679/