我正在尝试将Bootstrap应用于动态下拉列表。
我的代码无法与非MySQL的所有其他菜单项匹配 落下。 Here就是它的样子。
我的代码:
<li class = 'dropdown'>
<a href = '#' class = 'glyphicon glyphicon-book' >
<span class = 'caret'></span>
</a>
<select
onChange="window.location.href=this.value" class = 'dropdown-toggle'
data-toggle = 'dropdown' >
<ul class = 'dropdown-menu'>
<option>Training </option>
<?php
$sql = "SELECT * FROM sessions where event_type = 'training' ORDER BY
pro_title ";
$res = mysqli_query($con1, $sql);
if(mysqli_num_rows($res) > 0)
{
while($row = mysqli_fetch_array($res))
{
echo "<li><option value='mail/success.php?idx={$row['event_id']}'>{$row['pro_title']}</option></li>";
}
}
?>
</ul>
</select>
<li>
答案 0 :(得分:1)
请参见<select>和Native Form Widgets - DropDown Content
但是,在Bootstrap中,下拉列表是使用div元素或列表创建的。
根据您当前的代码,我假设您正在使用Bootstrap 3.x
以下是您可以尝试的示例:
<li class="dropdown">
<a href="#" class="glyphicon glyphicon-book dropdown-toggle" data-toggle="dropdown" role="button">
Training <span class='caret'></span>
</a>
<ul class="dropdown-menu">
<?php
$sql = "SELECT * FROM sessions where event_type = 'training' ORDER BY pro_title ";
$res = mysqli_query($con1, $sql);
if (mysqli_num_rows($res) > 0) {
while ($row = mysqli_fetch_array($res)) {
echo "<li><a href='mail/success.php?idx={$row['event_id']}'>{$row['pro_title']}</a></li>";
}
}
?>
</ul>
<li>
要了解有关该结构的更多信息,建议您查看以下链接(Bootstrap 3.x):
更新
<select onChange="window.location.href=this.value"> does the same as if you would click on the links in the dropdown <a href="somelink">text</a>
。
不过,您可以在单击以下项目时这样做:
尝试以下代码以呼应列表项:
echo "<li><a onclick='window.location.href=\"mail/success.php?idx={$row['event_id']}\">{$row['pro_title']}</a></li>";