我正试图在一个无线电组上监测这一变化。
我用的是下面的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>由于一个原因,当use选择另一个单选按钮时,checked属性不会被更新.
我想用javascript来监控变化,但现在,我无法得到无线电组的价值.
$('input[name=topcoat]').change(function(){ changed() });
function changed() {
id = $('input[name=topcoat]').val();
alert(id);
}发布于 2013-08-31 16:55:22
请这样做,我希望它能解决你的问题:
<script type="text/javascript">
$(function(){
$('input[name="topcoat"]').change(function(){ changed() });
function changed() {
id = $('input[name="topcoat"]:checked').val();
alert(id);
}
});
</script>https://stackoverflow.com/questions/18550221
复制相似问题