jQuery .val()为单选按钮返回undefined

Mdu*_*noj 2 html jquery radio-button

我试图在jQuery中获取已检查的单选按钮值.但它将值返回为"未定义".我搜索了这个问题的解决方案,但没有任何对我有用.

我的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>
Run Code Online (Sandbox Code Playgroud)

我的Jquery代码..

$(document).ready(function() {
    $(".service").change(function() {
        alert($(".service :checked").val());
    });
});
Run Code Online (Sandbox Code Playgroud)

这里是我问题的小提琴 ..

Ano*_*shi 7

classname和:checkedattribute 之间不应该有任何空格

 $(".service").change(function() {
        alert($(".service:checked").val());
    });
Run Code Online (Sandbox Code Playgroud)

小提琴