[英]Set Radio Button using value in jquery
How to set Radio button checked(select) using Attribute value 如何使用属性值设置单选按钮(选择)
html : HTML:
<div class="controls">
<input type="radio" id="chairs_canadd" name="chairs_canadd" value="1" />
<input type="radio" id="chairs_canadd" name="chairs_canadd" value="0" />
</div>
now im getting the value of chairs_canadd value from database via AJAX. 现在我通过AJAX从数据库中获取chairs_canadd值。 if the value is 0 then the second have to get selected , if the value is 1 then first one has to be get selected. 如果值为0则必须选择第二个,如果值为1,则必须先选择第一个。
You have value for option that needs to be set in variable chairs_canadd
. 您有需要在变量chairs_canadd
设置的选项的值。 you can get the radio button by value and then set it. 您可以按值获取单选按钮然后进行设置。 Like this: 像这样:
$(".controls input[value="+chairs_canadd+"]").prop("checked", true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.