首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单选按钮选中属性,不更新用户操作

单选按钮选中属性,不更新用户操作
EN

Stack Overflow用户
提问于 2013-08-31 16:24:05
回答 1查看 2.8K关注 0票数 0

我正试图在一个无线电组上监测这一变化。

我用的是下面的HTML:

代码语言:javascript
复制
<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>

由于一个原因,当use选择另一个单选按钮时,checked属性不会被更新.

我想用javascript来监控变化,但现在,我无法得到无线电组的价值.

代码语言:javascript
复制
$('input[name=topcoat]').change(function(){ changed() });

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

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-31 16:55:22

请这样做,我希望它能解决你的问题:

代码语言:javascript
复制
<script type="text/javascript">
$(function(){

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

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

});

</script>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18550221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档