Possible Duplicate:
how to check a radio button with jQuery?
如何更改单选按钮的值。
jQuery('input:radio[name=search][id=search-damages]').checked = true;
我试过了,但是不行
<input type="radio" name="search" id="search-vehicle" value="search-vehicle" checked>
<input type="radio" name="search" id="search-damages" value="search-damages">
How to change a radio button value?
checked
属性不会更改单选按钮的值。请注意,checked
属性是 DOM INPUT 元素属性之一,而不是 jQuery 对象属性之一(通过使用 jQuery 选择一个元素,将创建一个 jQuery 对象)。如果您想更改此属性,您应该首先将 jQuery 对象转换为 DOM 元素对象。
$('#search-damages')[0].checked = true;
或者使用 jQuery 对象的 prop()
方法:
$('#search-damages').prop('checked', true)
如果你想改变输入的值,你可以使用 jQuery val()
方法:
$('#search-damages').val('new value');