错误:ReferenceError:事件未定义

编程入门 行业动态 更新时间:2024-10-22 02:46:26
本文介绍了错误:ReferenceError:事件未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请帮助以下代码.

我在Firefox和IE上收到未定义事件"错误.

I am getting "event is not defined" error on firefox and ie.

问题似乎与event.preventDefault();

The issue appears tobe with event.preventDefault();

此CSS只是关闭了下拉菜单

this css just turns off the drop-down menu

<style type="text/css"> .dropdown { display: none; opacity: 0; } </style>

jquery

jquery

自定义javascript

custom javascript

<script type="text/javascript"> $( document ).ready(function(){ jQuery('.download-dropdown > a').click( function() { event.preventDefault(); var $this=jQuery(this); if (!$this.parent().hasClass('active')) { var top=$this.parent().offset().top; var left=$this.parent().offset().left; jQuery('body').append($this.parent()); $this.parent().addClass('active'); $this.parent().css({ 'position': 'absolute', 'top': top, 'left': left, 'z-index': 999}); $this.parent().children('.dropdown').animate({ 'opacity': '1','height': 'toggle'}); $this.parent().animate({'height': '400'}); window.dropdown=$this; } else { $this.parent().css({ 'position': 'relative', 'top': 'inherit', 'left': 'inherit', 'z-index': 1}); $this.parent().removeClass('active'); jQuery('article.contact-download > div > section > div').append($this.parent()); $this.parent().children('.dropdown').animate({ 'opacity': '0','height': 'toggle'}); $this.parent().animate({'height': '45'}); } }); }); </script>

这是html

<article class="contact-download" data-background-height="60"> <section data-speed="0"> <div> <div class="download-dropdown" style="height: 60px; position: relative; z-index: 1; top: inherit; left: inherit; display: inline-table"> <a style="padding-left: 25px; text-decoration:none; " href="#">click to see more</a> <div class="dropdown"> <ul> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li> <li><a href="#">Link 4</a></li> </ul> </div> </div> </div> </section> </article>

推荐答案

您需要将is设置为函数参数:

You need to set is as a function parameter:

jQuery('.download-dropdown > a').click( function(event) { // event is defined now __^__

更多推荐

错误:ReferenceError:事件未定义

本文发布于:2023-11-28 06:56:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641375.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   事件   未定义   ReferenceError

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!