在我的网页中,我对下拉选项卡使用了点击事件。但代码对我不起作用。 但是如果我使用悬停而不是点击事件它工作得很好。但是我需要在我的网页代码中使用点击是:
$(document).ready(function(){
var dropDownSpeed = 200;
var dropUpSpeed = 200;
var menuHeight = '240px';
var tabs = $("#tabs");
var tabPanesContainer = $("ul#tabPanes");
var tabPanesAll = tabPanesContainer.find("li").css("position", "absolute");
$(".slide").click(function () {
var thisMenuItem = $(this);
/*get the offset of this item in respect to the page*/
var thisMargin = thisMenuItem.offset().center;
/*get the offset of the navigation bar in respect to the page*/
var tabsOffset = tabs.offset().center;
var thisIndex = thisMenuItem.index();
thisMargin = Math.floor(thisMargin - tabsOffset);
var thisOffset = thisMargin - 52;
/* handle IE margin difference*/
if($.browser.msie)
{
thisOffset = thisMargin - 15;
}
tabPanesContainer.css('margin-left', thisOffset);
tabPanesContainer.stop().animate({
height: menuHeight
}, dropDownSpeed);
tabMenuLinks.removeClass('activeTab');
thisMenuItem.addClass('activeTab');
var thisHash = thisMenuItem.find("a").attr('href');
var tabClicked = tabPanesAll.filter(thisHash);
tabClicked.appendTo(tabPanesContainer).show();
return false;
}, function() {
$(this).stop();
});
});
});
请帮我解决问题谢谢...
最佳答案
您的点击事件语法错误
..
它只接受一个函数处理程序,而不是你写的两个
$(".slide").click(function () {
// Click event code
}, function() {
$(this).stop();
});
它适用于悬停事件,因为它可以接受两个处理函数..
要使点击事件生效,您的签名必须是
$(".slide").click(function () {
// Click event code
});
// Remove the other function
关于Jquery 点击事件不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14265658/