Link 忽略 jquery 以显示子导航
Link ignoring jquery to show sub nav
我创建了一个带有 link 的菜单,当您单击它时,它会显示一个子导航。这适用于除 Firefox 之外的所有浏览器。
点击 link 后,它实际上进入了页面,而不是弹出子导航。这是我的 jquery:
<script type="text/javascript">
jQuery(function($) {
$(document).ready(function() {
$('.expander').click(function() {
event.preventDefault();
$(this).next('.expanded').first().toggle();
});
});
});
</script>
知道为什么要这样做吗?
你的 event
是 undefined
在函数中声明它就像这样:-
$('.expander').click(function(event) { //here
event.preventDefault();
$(this).next('.expanded').first().toggle();
});
如果您正在使用 jQuery(function($) {
,您不需要 $(document).ready(function() {
,您应该删除它。
我创建了一个带有 link 的菜单,当您单击它时,它会显示一个子导航。这适用于除 Firefox 之外的所有浏览器。
点击 link 后,它实际上进入了页面,而不是弹出子导航。这是我的 jquery:
<script type="text/javascript">
jQuery(function($) {
$(document).ready(function() {
$('.expander').click(function() {
event.preventDefault();
$(this).next('.expanded').first().toggle();
});
});
});
</script>
知道为什么要这样做吗?
你的 event
是 undefined
在函数中声明它就像这样:-
$('.expander').click(function(event) { //here
event.preventDefault();
$(this).next('.expanded').first().toggle();
});
如果您正在使用 jQuery(function($) {
,您不需要 $(document).ready(function() {
,您应该删除它。