Javascript 单选按钮选中属性未在用户操作时更新

Javascript 单选按钮选中属性未在用户操作时更新,javascript,jquery,html,radio-button,Javascript,Jquery,Html,Radio Button,我正试着监测一个广播电台的变化 我正在将topcoat与以下HTML一起使用: <ul class="topcoat-list"> <li class="topcoat-list__item"> <label class="topcoat-radio-button__label"> <input type="radio" name="topcoat" value="1" checked="checked"&g

我正试着监测一个广播电台的变化

我正在将topcoat与以下HTML一起使用:

<ul class="topcoat-list">
    <li class="topcoat-list__item">
       <label class="topcoat-radio-button__label">
            <input type="radio" name="topcoat" value="1" checked="checked">
            <div class="topcoat-radio-button"></div>
            Test1
        </label>
    </li>
    <li class="topcoat-list__item">
        <label class="topcoat-radio-button__label">
            <input type="radio" name="topcoat" value="2">
            <div class="topcoat-radio-button"></div>
            Test2
        </label>
    </li>
    <li class="topcoat-list__item">
        <label class="topcoat-radio-button__label">
            <input type="radio" name="topcoat" value="3">
            <div class="topcoat-radio-button"></div>
            Test3
        </label>
    </li>
</ul>

请尝试这种方式,我希望它能解决您的问题:

<script type="text/javascript">
$(function(){

$('input[name="topcoat"]').change(function(){ changed() });

function changed() {
  id = $('input[name="topcoat"]:checked').val();
  alert(id);
}

});

</script>

$(函数(){
$('input[name=“topcoat”]').change(function(){changed()});
函数已更改(){
id=$('input[name=“topcoat”]:checked').val();
警报(id);
}
});

当您选中复选框时,它是一个更新的属性,而不是属性。您可以使用
$('input[name=“topcat”]:checked')获取所选项目。val()
@ArunPJohny,您的评论解决了我的问题。我把答案记下来表示接受(我不知道你们中谁是第一个)。
<script type="text/javascript">
$(function(){

$('input[name="topcoat"]').change(function(){ changed() });

function changed() {
  id = $('input[name="topcoat"]:checked').val();
  alert(id);
}

});

</script>