我正在尝试在CSS中创建一个下拉菜单,并在Django中获取所选选项的值以进行处理。我怎么能做到这一点?我使用文本框HTML尝试了我的代码,并且能够使用request.get函数获取数据,但是如何使用CSS下拉菜单完成此操作。
CSS示例(W3学校):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyPage</title>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
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);
z-index: 1;
}
.dropdown-content a {
color: black;
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: #3e8e41;
}
</style>
</head>
<body>
<h2>Hoverable Dropdown</h2>
<p>Move the mouse over the button to open the dropdown menu.</p>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="someurlwhichhasaviewattached" name="Linke">XXX</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
</body>
</body>
</html>
如果用户选择XXX,我如何在后台检索它?
答案 0 :(得分:0)
如果要选择“XXX”,则必须使用选择框。 像这样:
.styled select {
background: transparent;
width: 150px;
font-size: 16px;
border: 1px solid #ccc;
height: 34px;
}
.styled{
margin: 50px;
width: 120px;
height: 34px;
border: 1px solid #111;
border-radius: 3px;
overflow: hidden;
background:#ddd;
}
<div class="styled">
<select>
<option selected>Dropdown</option>
<option>XXX</option>
<option>Link 2</option>
<option>Link 3</option>
</select>
</div>