站內搜尋

Friday, June 12, 2015

[jQuery] 指定某個 radio button 被選取 (使用 prop )

HTML code 如下:
<input type="radio" name="no" value="1">1<br>
<input type="radio" name="no" value="2">2<br>
<input type="radio" name="no" value="3">3<br>
<button type="button" id="btn">選取2</button>
jQuer code 如下:
$("#btn").on("click", function() {
  $("input[name='no'][value='2']").prop("checked", true);
});

No comments:

Post a Comment