打开面板组时,选中单选按钮

时间:2014-08-11 13:14:59

标签: jquery twitter-bootstrap twitter-bootstrap-3 accordion jquery-ui-accordion

我试图在stackoverflow中应用其他一些教程来实现这一点,但没有成功,我不知道我做错了什么......

所以上面的代码是我当前的可折叠组面板,我想要实现的是: 当我点击其中一个时,我想要检查radiobutton,任何提示?

        <div class="panel-group" id="panel-payment-options">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <a class="panel-title" data-toggle="collapse" data-parent="#panel-payment-options" href="#panel-credit-card">
                        <label for="credit-card">
                            <input type="radio" value="credit-card" id="credit-card" name="paymentmethod"> Cartão de Crédito
                        </label>
                    </a>
                </div>
                <div id="panel-credit-card" class="panel-collapse collapse in">
                    <div class="panel-body">
                        Content for credit card
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <a class="panel-title" data-toggle="collapse" data-parent="#panel-payment-options" href="#panel-internet-banking">
                        <label for="internet-banking">
                            <input type="radio" name="paymentmethod" id="internet-banking" value="internet-banking"> Internet Banking
                        </label>
                    </a>
                </div>
                <div id="panel-internet-banking" class="panel-collapse collapse">
                    <div class="panel-body">
                        Content for internet banking
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <a class="panel-title" data-toggle="collapse" data-parent="#panel-payment-options" href="#panel-boleto">
                        <label for="boleto">
                            <input type="radio" name="paymentmethod" id="boleto" value="boleto"> Boleto
                        </label>
                    </a>
                </div>
                <div id="panel-boleto" class="panel-collapse collapse">
                    <div class="panel-body">
                        content for boleto
                    </div>
                </div>
            </div>
        </div>

1 个答案:

答案 0 :(得分:1)

添加此JQuery 3行:

$(".panel-title").click(function() {
    $(this).children().children().prop("checked", true);
});

Try Demo