我想要在jQuery中检查单选按钮的值。但它返回值为'未定义'。我搜索了这个问题的解决方案,但没有为我工作。jQuery .val()返回undefined的单选按钮
我的HTML代码。
<label><input type="radio" class="service" name="service" id="all-service" value="all-service"> All Service</label><br>
<label><input type="radio" class="service" name="service" id="electrician" value="Electrician"> Electrician</label><br>
<label><input type="radio" class="service" name="service" id="painter" value="Painter"> Painter</label><br>
<label><input type="radio" class="service" name="service" id="photo and video coverage" value="Photo and Video Coverage"> Photo and Video Coverage</label>
我的jQuery代码..
$(document).ready(function() {
$(".service").change(function() {
alert($(".service :checked").val());
});
});
这里fiddle我的问题..
删除多余的空格应该是' “服务:检查”'。空间意味着你通过后代搜索。 – Regent