HTML:
<div class='row homes center'>
<div class='span1'></div>
<div class='row homes center'>
<div class='span1'></div>
<div class='hometype span2'>
<div class='checked'></div>
<label for='prairie'>
<img src='img/prairie.png' >
</label>
<input id='prairie' name='hometypes' type='checkbox' value='Prairie'>
</div>
<div class='hometype span2'>
<div class='checked'></div>
<label for='traditional'>
<img src='img/traditional.png'>
</label>
<input id='traditional' name='hometypes' type='checkbox' value='Traditional'>
</div>
<div class='hometype span2'>
<div class='checked'></div>
<label for='transitional'>
<img src='img/transitional.png'>
</label>
<input id='transitional' name='hometypes' type='checkbox' value='Transitional'>
</div>
<div class='hometype span2'>
<div class='checked'></div>
<label for='bungalow'>
<img src='img/bungalow.png'>
</label>
<input id='bungalow' name='hometypes' type='checkbox' value="Bungalow">
</div>
</div>
<div class='fixed_button homes hidden'>
<a class='button blue_button continue continue_type'>Continue →</a>
</div>
</div>
jQuery:
$('.choose_style input[type="checkbox"]').on('change', function () {
if ($('input[name=homestyles]:checked').val()) {
$('.homes').removeClass('hidden');
}
});
我需要的按钮,以显示任何复选框被选中。但是,单击复选框时不会发生任何反应。我做错了什么?我需要移除按钮上的.hidden
。
发布于 2013-11-26 01:30:36
如果检查了集合中的任何元素,则.is(':checked')
返回true:
$('.choose_style input[type="checkbox"]').on('change', function () {
if ( $('input[name=homestyles]').is(':checked') ) {
$('.homes').removeClass('hidden');
}
});
注意到发布的标记没有.choose_style
或homestyles
元素吗?
发布于 2013-11-26 01:35:17
你的代码中有太多的错误。我修复了其中的几个以使其正常工作http://jsfiddle.net/aamir/jNU4B/
$('input[type="checkbox"]').on('change', function () {
if ($('input[name=homestyles]:checked')) {
$('.homes').removeClass('hidden');
}
});
https://stackoverflow.com/questions/20199381
复制相似问题