当我舔li时,我想要的是下拉列表。
然而,由于某些原因,它无法正常工作。
$document.read(function(){
var mainnav = $('#main-nav'),
openActive = mainnav.is ('.open-active'),
navActive = mainnav.find ('> .active');
mainnav.find ('> .dropdown > a').bind ('click', navClick);
if (openActive && navActive.is ('.dropdown')) {
navActive.addClass ('opened').find ('.sub-nav').show ();
}
function navClick (e) {
e.preventDefault ();
var li = $(this).parents ('li');
if (li.is ('.opened')) {
closeAll ();
} else {
closeAll ();
li.addClass ('opened').find ('.sub-nav').slideDown ();
}
}
function closeAll () {
$('.sub-nav').slideUp ().parents ('li').removeClass ('opened');
}
});
如您所见,我已将正确的操作绑定到a tag
感谢您的帮助,时间和精力。
答案 0 :(得分:2)
$document.read
(第一行)是拼写错误,还是这是您的实际代码?如果是,那就解决它;它应该是$(document).ready
。
答案 1 :(得分:2)
请在您的代码中更正文档... $(document).ready 只需替换此
$document.read
带
$(document).ready
答案 2 :(得分:0)
在您的代码中,将$document.read(function(){})
更改为$(document).ready(function(){// place your code here})
或$(function(){ // place your code here})
答案 3 :(得分:-1)
ready()
函数声明中存在拼写错误,您应该声明ready()
而不是read()
:
$(document).ready(function(){ //Here is the typo
var mainnav = $('#main-nav'),
openActive = mainnav.is ('.open-active'),
navActive = mainnav.find ('> .active');
mainnav.find ('> .dropdown > a').bind ('click', navClick);
if (openActive && navActive.is ('.dropdown')) {
navActive.addClass ('opened').find ('.sub-nav').show ();
}
function navClick (e) {
e.preventDefault ();
var li = $(this).parents ('li');
if (li.is ('.opened')) {
closeAll ();
} else {
closeAll ();
li.addClass ('opened').find ('.sub-nav').slideDown ();
}
}
function closeAll () {
$('.sub-nav').slideUp ().parents ('li').removeClass ('opened');
}
});