Jquery 点击事件不工作

标签 jquery css

在我的网页中,我对下拉选项卡使用了点击事件。但代码对我不起作用。 但是如果我使用悬停而不是点击事件它工作得很好。但是我需要在我的网页代码中使用点击是:

  $(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/

相关文章:

javascript - 输入焦点时隐藏 ios 设备上的键盘

javascript - 如何在 React Native 中使用 AnimatedCircularProgress 正确定位 View

javascript - 如何使用新行调整文本框的大小

javascript - 从提交的表单中获取所有输入

jquery - ListView 无法在 jQuery Mobile 中工作

javascript - 如何覆盖函数?

html - 什么是完成我的 "cross?"的简单 CSS 方法

jQuery Ajax 错误处理,显示自定义异常消息

javascript - 视差效果 - 消除部分之间的差距

css - 您如何使视频响应不同的尺寸?