[英]Why my menu doesn't dropdown?
我只是在為我的網站使用“登錄” /“注冊”下拉菜單,但無法弄清楚為什么它不能正常工作。
我是jQuery的初學者,所以問題可能出在其中。 還是可能與HTMl或CSS有關,我不確定。 當我測試頁面並打開控制台時,jQuery不會顯示任何錯誤,因此我不確定問題出在哪里。 這是代碼:
HTML:
<div id="navthing">
<h2><a href="#" id="loginform">Log in</a> | <a href="#">Sign Up</a></h2>
<div class="login">
<div class="arrow-up"></div>
<div class="formholder">
<div class="randompad">
<fieldset>
<label name="email">Email</label>
<input type="email" value="example@example.com" />
<label name="password">Password</label>
<input type="password" />
<input type="submit" value="Login" />
</fieldset>
</div>
</div>
</div>
</div>
CSS:
#navthing {
text-align: right;
padding: 0.5em;
}
.login {
position: relative;
width:250px;
display:none;
}
.arrow-up {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 15px solid #ECF0F1;
left: 10%;
position: absolute;
top: -10px;
}
.formholder input[type="email"], .formholder input[type="password"] {
padding: 7px 5px;
margin: 10px 0;
width: 96%;
display: block;
font-size: 18px;
border-radius: 5px;
border: none;
-webkit-transition: 0.3s linear;
-moz-transition: 0.3s linear;
-o-transition: 0.3s linear;
transition: 0.3s linear;
}
.formholder input[type="email"]:focus, .formholder input[type="password"]:focus {
outline: none;
box-shadow: 0 0 1px 1px #1abc9c;
}
.formholder input[type="submit"] {
background: #1abc9c;
padding: 10px;
font-size: 20px;
display: block;
width: 100%;
border: none;
color: #fff;
border-radius: 5px;
}
.formholder input[type="submit"]:hover {
background: #1bc6a4;
}
.randompad {
padding: 10px;
}
.green {
color: #1abc9c;
}
a {
color: #ecf0f1;
text-decoration: none;
}
a:hover {
color: #1abc9c;
}
jQuery的:
$('input[type="submit"]').mousedown(function(){
$(this).css('background', '#2ecc71');
});
$('input[type="submit"]').mouseup(function(){
$(this).css('background', '#1abc9c');
});
$('#loginform').click(function(){
$('.login').fadeToggle('slow');
$(this).toggleClass('green');
});
$(document).mouseup(function (e)
{
var container = $(".login");
if (!container.is(e.target)
&& container.has(e.target).length === 0)
{
container.hide();
$('#loginform').removeClass('green');
}
});
它顯示還可以,但是當我單擊“登錄”時沒有下拉菜單。 怎么了? 謝謝。
編輯1: html頁面的標題包括這些文件:
<head>
<meta charset="utf-8">
{% load staticfiles %}
<title>{% block title %}Index{% endblock %}</title>
{% load static from staticfiles %}
{% block style_base %}
<link href="{% static 'css/styles.css' %}" rel="stylesheet">
{% endblock %}
<meta name="description" content="{% block description %}{% endblock %}">
<link href='https://fonts.googleapis.com/css?family=Roboto+Mono:400,700,300' rel='stylesheet' type='text/css'>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="static/js/jquery.min.js" type="text/javascript"></script>
<script src="static/js/main.js" type="text/javascript"></script>
<script src="static/js/login3.js" type="text/javascript"></script>
</head>
這里有兩個jQuery源,但是我只嘗試了其中一個都沒有結果。 網站上(在main.js中)也有一個使用jQuery且工作正常的滑塊。
當我加載頁面時,它會出現“登錄| 注冊,但是當我單擊“登錄”按鈕時沒有任何反應(沒有下拉菜單,什么也沒有)。
在您的jquery代碼的第一部分中,我添加了此代碼,它的工作原理是:
$( document ).ready(function() {
});
說明: https : //api.jquery.com/ready/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.