首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >显示div on复选框选择

显示div on复选框选择
EN

Stack Overflow用户
提问于 2013-11-26 01:28:09
回答 2查看 69关注 0票数 0

HTML:

代码语言:javascript
复制
<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 &rarr;</a>
  </div>
</div>

jQuery:

代码语言:javascript
复制
$('.choose_style input[type="checkbox"]').on('change', function () {
  if ($('input[name=homestyles]:checked').val()) {
    $('.homes').removeClass('hidden');
  }
});

我需要的按钮,以显示任何复选框被选中。但是,单击复选框时不会发生任何反应。我做错了什么?我需要移除按钮上的.hidden

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-26 01:30:36

如果检查了集合中的任何元素,则.is(':checked')返回true:

代码语言:javascript
复制
$('.choose_style input[type="checkbox"]').on('change', function () {
    if ( $('input[name=homestyles]').is(':checked') ) {           
        $('.homes').removeClass('hidden');
    }
});

注意到发布的标记没有.choose_stylehomestyles元素吗?

票数 0
EN

Stack Overflow用户

发布于 2013-11-26 01:35:17

你的代码中有太多的错误。我修复了其中的几个以使其正常工作http://jsfiddle.net/aamir/jNU4B/

代码语言:javascript
复制
$('input[type="checkbox"]').on('change', function () {
    if ($('input[name=homestyles]:checked')) {
        $('.homes').removeClass('hidden');
    }
 });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20199381

复制
相关文章

相似问题

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