[英]How to select multiple elements by id using jQuery
我有兩個單選按鈕:
<p>
<label for="input_1">Path to Excellent </label>
<input id="input_1" name="radio" type="radio" value="1" />
</p>
<p>
<label for="input_2">Award of Excellence</label>
<input id="input_2" name="radio" type="radio" value="2" />
</p>
我想從其中一個使用val()使用其id:jQuery的“ input_1”或“ input_2”,如下所示:
$('input[#input_1,#input_2]:checked').val();
我的目標是從其中之一通過id獲取val()。 我怎樣才能做到這一點?
在這種情況下,您可以檢查id
的開頭 :
$("input[id^='input_']:checked").val();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.