【发布时间】:2016-07-20 21:42:29
【问题描述】:
目前我有一个下拉菜单。此下拉菜单将显示我的数据库的一列数据。这对我来说很好。
但是,我想实现此功能:当用户单击下拉菜单中的一个选项时,页面将为用户提供一个包含他单击的选项的短语,例如“您选择 [他单击的选项]!”。
我应该怎么做才能做到这一点?
这是我的下拉菜单代码:
<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
background-color: #3D85C6;
color: white;
font-family: sans-serif;
font-weight: bold;
font-size: 18px;
padding: 18px;
border: none;
cursor: pointer; }
.dropdown {
position: left;
display: inline-block; }
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); }
.dropdown-content a {
color: black;
font-family: sans-serif;
padding: 12px 16px;
text-decoration: none;
display: block; }
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block; }
.dropdown:hover .dropbtn {
background-color: #3D85C6; }
</style>
</head>
<body>
<div class="dropdown">
<button class="dropbtn">Orgnazitions</button>
<div class="dropdown-content">
<?php
$db = new mysqli('localhost:8889', 'root', 'root', 'VBS');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = "SELECT * FROM Orgnazition";
if (!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while ($row = $result->fetch_assoc()) {
echo "<a href='choose.php'>".$row['OrgName']."</a>";
} ?>
</div>
</div>
</body>
</html>
【问题讨论】:
-
使用 Javascript,而不是 PHP。 ----> onclick 显示选择的选项