Bootstrap DropDown自动选择

时间:2015-06-10 14:59:43

标签: php jquery twitter-bootstrap drop-down-menu

我使用bootstrap下拉增强功能,有没有办法可以根据从数据库中提取的值预先选择其中一个下拉选项?我已尝试过以下适用于普通单选按钮的功能,但它并不适用于此。我猜测因为它的引导程序可能需要在某处添加某种.active或.selected。

        <!-- Email -->
        <div class="form-group">
            <label for="pri_email" class="col-sm-3 control-label">Primary email</label>
            <div class="col-sm-9">
                <div class="input-group">
                <input type="email" class="form-control" id="pri_email" placeholder="Email" name="pri_email" value="<?php echo $row_ShowContact[0]['pri_email'];?>">
                <div class="btn-group input-group-btn">
                    <button data-toggle="dropdown" class="btn btn-default dropdown-toggle">Home <span class="caret" style="margin-left: 4px"></span></button>
                    <ul class="dropdown-menu">
                        <li><input type="radio" id="pri_email_home" name="pri_email_type" value="home" <?php if (!(strcmp("home", $row_ShowContact[0]['pri_email_type']))) {echo "checked=\"checked\"";} ?>><label for="pri_email_home">Home</label></li>
                        <li><input type="radio" id="pri_email_work" name="pri_email_type" value="work" <?php if (!(strcmp("work", $row_ShowContact[0]['pri_email_type']))) {echo "checked=\"checked\"";} ?>><label for="pri_email_work">Work</label></li>
                        <li><input type="radio" id="pri_email_marketing" name="pri_email_type" value="marketing" <?php if (!(strcmp("marketing ", $row_ShowContact[0]['pri_email_type']))) {echo "checked=\"checked\"";} ?>><label for="pri_email_marketing">Marketing</label></li>
                        <li><input type="radio" id="pri_email_invoice" name="pri_email_type" value="invoice" <?php if (!(strcmp("invoice", $row_ShowContact[0]['pri_email_type']))) {echo "checked=\"checked\"";} ?>><label for="pri_email_invoice" >Invoice</label></li>

                    </ul>
                </div>
                </div>
            </div>
        </div>

一般情况下,下拉列表工作正常,value的{​​{1}}正存储在数据库中 - 我只想重新调用它。

感谢。

1 个答案:

答案 0 :(得分:0)

我用上面的代码解决了自己,因为我改变了这个......

<button data-toggle="dropdown" class="btn btn-default dropdown-toggle">Home <span class="caret" style="margin-left: 4px"></span></button>

到此......

<button data-toggle="dropdown" class="btn btn-default dropdown-toggle"><?php if($row_ShowContact[0]['pri_email_type'] == ""){echo "Home";}else{echo ucfirst($row_ShowContact[0]['pri_email_type']);}?> <span class="caret" style="margin-left: 4px"></span></button>