0

ラジオグループの変更を監視しようとしています。

次の 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>

よくわからない理由でchecked、使用者が別のラジオボタンを選択したときに属性が更新されません...

javascriptで変化を監視できるようにしたいのですが、今のところラジオグループの値が取得できません...

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

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

1 に答える 1

1

この方法を試してください。問題が解決することを願っています:

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

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

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

});

</script>
于 2013-08-31T16:55:22.507 に答える