php - 我的 Bootstrap 不工作,试图包含 Mysql 下拉菜单
问题描述
我正在尝试将 Bootstrap 应用于动态下拉菜单。
我的代码无法匹配所有其他不是 Mysql 下拉菜单的菜单项。这是它的样子。
我的代码:
<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>
解决方案
<select> 元素必须有 <option> 元素作为子元素。
然而,在 Bootstrap 中,DropDowns 是使用 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>";
推荐阅读
- powershell - 从 powershell 运行 cosmosdb 命令
- javascript - javascript作为关键字,导入中“as”后的多个名称
- python-3.x - 将字符串更改为字节,但格式为字符串
- html - 使用 XPath 表达式从 HTML span 元素中提取全文
- gatsby - Gatsby 自动链接标头不生成锚链接
- python - Discord.py bot 未与 firebase 实时数据库连接
- java - 将 Firebase 图像作为可绘制对象检索并显示在回收站视图中
- r - 提高 RStudio 图形设备的质量(预览)
- javascript - 使用 React 向 Binance API 发出 GET 请求时遇到问题
- python - Python:根据条件拆分单列