【问题标题】:Bootstrap CheckBox Into TabPanel Tab Doesn't Check/Uncheck引导复选框进入 TabPanel 选项卡不选中/取消选中
【发布时间】:2014-07-17 09:40:19
【问题描述】:

问题是选项卡面板选项卡内的复选框不检查。

JSFiddle link

HTML代码在这里:

<ul class="nav nav-tabs" id="myTab">
    <li class="active">
        <a href="#home">
            <div style="margin: 0;" class="checkbox">
                <label style="float: left;">
                    <input style="display: inline-block;" type="checkbox" id="product" value="home" />
                    <div style="display: inline-block;">Home</div>
                </label>
            </div>
        </a>
    </li>
    <li>
        <a href="#profiles">
            <div style="margin: 0;" class="checkbox">
                <label style="float: left;">
                    <input style="display: inline-block;" type="checkbox" id="product" value="profiles" />
                    <div style="display: inline-block;">Profiles</div>
                </label>
            </div>
        </a>
    </li>
    <li>
        <a href="#messages">
            <div style="margin: 0;" class="checkbox">
                <label style="float: left;">
                    <input style="display: inline-block;" type="checkbox" id="product" value="messages" />
                    <div style="display: inline-block;">Messages</div>
                </label>
            </div>
        </a>
    </li>
</ul>

有什么想法吗?如何让这些复选框执行选中和取消选中功能?

【问题讨论】:

  • 为什么每个复选框都有相同的ID?
  • 因为这只是一个例子。将 id 更改为唯一并没有给我所需的结果。
  • Bunga :检查我的答案。是的,id 应该是唯一的。

标签: javascript php jquery html twitter-bootstrap


【解决方案1】:

你的 jquery 会是

$('#myTab li').click(function (e) {
 // e.preventDefault();
    $(this).find('a').tab('show');
 // $(this).tab('show');
     $(this).closest('ul').find('input[type="checkbox"]').prop('checked','');
     $(this).closest('li').find('input[type="checkbox"]').prop('checked','checked');

});

DEMO

【讨论】:

【解决方案2】:

您正在阻止它点击。删除e.preventDefault() 即可解决问题

【讨论】:

  • 只删除该行,当您移动到其他选项卡时不会取消选中您的复选框。
猜你喜欢
  • 2014-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-15
  • 2014-05-28
  • 1970-01-01
  • 1970-01-01
  • 2019-01-28
相关资源
最近更新 更多