jQuery没有';t工作| Wordpress顶部菜单
编辑:我通过。。。加载jquery库时,我认为jquery可以像JavaScript一样工作,无需导入任何内容。很抱歉把你的时间浪费在一个愚蠢的问题上 // 这是wordpress插件,它使用jQuery修复IE6中顶部菜单(悬停效果)的显示 我想要的是实现主题中的功能,同时消除插件的需要 如果我把这部分放进去,我会犯错误jQuery没有';t工作| Wordpress顶部菜单,jquery,wordpress,drop-down-menu,Jquery,Wordpress,Drop Down Menu,编辑:我通过。。。加载jquery库时,我认为jquery可以像JavaScript一样工作,无需导入任何内容。很抱歉把你的时间浪费在一个愚蠢的问题上 // 这是wordpress插件,它使用jQuery修复IE6中顶部菜单(悬停效果)的显示 我想要的是实现主题中的功能,同时消除插件的需要 如果我把这部分放进去,我会犯错误 <script type="text/javascript"> jQuery(document).ready( function($) { $(
<script type="text/javascript">
jQuery(document).ready( function($) {
$('#access li').mouseover( function() {
$(this).find('ul').show();
});
$('#access li').mouseleave( function() {
$(this).find('ul').hide();
});
$('#access li ul').mouseleave( function() {
$(this).hide();
});
});
</script>
我试过了。现在我犯了两个错误
Uncaught ReferenceError: $ is not defined
Uncaught ReferenceError: jQuery is not defined
在查看了错误之后,它变得更加清晰,但仍然不确定它为什么不工作
//
我认为jquery可以像JavaScript一样工作,而不需要导入任何东西;D
Wordpress插件源代码:
<?php
/**
* Plugin Name: Twentyten IE6 Menus
* Author: Sara Cannon
* Author URI: http://sara-cannon.com
* Description: Make the menu drop down in IE6 (if you care about that sort of thing)
* Version: 1.0
* License: GPL2
*/
function sara_twentyten_ie6_menus_enqueue() {
wp_enqueue_script( 'jquery' );
}
add_action( 'after_setup_theme', 'sara_twentyten_ie6_menus_enqueue' );
function sara_twentyten_ie6_menus_script() {
?>
<!--[if lte IE 6]>
<script type="text/javascript">
jQuery(document).ready( function($) {
$('#access li').mouseover( function() {
$(this).find('ul').show();
});
$('#access li').mouseleave( function() {
$(this).find('ul').hide();
});
$('#access li ul').mouseleave( function() {
$(this).hide();
});
});
</script>
<![endif]-->
<?php
}
add_action( 'wp_footer', 'sara_twentyten_ie6_menus_script' );
jQuery不在.ready(函数(){})上传递任何内容
试试这个:
(function($, window, document, undefined) {
$(function() {
$('#access li').mouseover( function() {
$(this).find('ul').show();
});
$('#access li').mouseleave( function() {
$(this).find('ul').hide();
});
$('#access li ul').mouseleave( function() {
$(this).hide();
});
});
})(jQuery, window, document);
如果您正确导入jQuery,则在此块内不应未定义jQuery($)。firebug中的JS错误?您是否手动链接jQuery?这个问题一团糟。
(function($, window, document, undefined) {
$(function() {
$('#access li').mouseover( function() {
$(this).find('ul').show();
});
$('#access li').mouseleave( function() {
$(this).find('ul').hide();
});
$('#access li ul').mouseleave( function() {
$(this).hide();
});
});
})(jQuery, window, document);