如何根据值选择元素

How to select an element according a value

本文关键字:选择 元素 何根      更新时间:2023-09-26

如何根据值选择元素? 例如,我想在控件中选择具有value=2 RadiobuttonList输入。

谢谢

$('#{id of RadiobuttonList} input[value="2"]').attr('checked', 'checked')

或者对于 jQuery 1.6+:

$('#{id of RadiobuttonList} input[value="2"]').prop('checked', true)

您可以使用此 CSS 选择器:

input[type="radio"][value="2"]

在 jquery 中

$('input[type="radio"][value="2"]')
你可以

试试

$("#<%=rbl.ClientID%> input[value=2]").attr('checked', true);  

$('#<%=rbl.ClientID %>').find("input[value=2]").attr("checked", "checked");

注意 rbl 是单选按钮列表的 ID