希望这个对你们来说很容易解决:)
我正在构建一个wordpress主题,之前在html head标签中调用jquery脚本相当糟糕.这导致Opera中的一些加载延迟,我怀疑是因为我试图以两种方式同时加载jquery ...无论如何我现在正在functions.php文件中正确地执行它,但是我的进一步脚本依赖于jquery不是很好玩.
这里是我现在如何排队jquery和我的脚本(用于滑动面板)的片段:
add_action('init', 'my_init');
function my_init() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', false, '1.4.2', true);
wp_enqueue_script('jquery');
wp_enqueue_script('slide_script', get_template_directory_uri() . '/scripts/slide.js');
echo "alert( 'Hello Admin!' );";
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的滑动面板脚本:
$(document).ready(function(){
$(".btn-slide").click(function(){
var $marginLefty = $("#slide-panel");
$marginLefty.animate({
marginLeft: parseInt($marginLefty.css('marginLeft'),10) == 0 ?
$marginLefty.outerWidth() :
0
});
});
});
Run Code Online (Sandbox Code Playgroud)
当我刚刚在head标签中调用jquery然后直接将脚本放在脚本标签中时,这一切都很有效,但现在firebug显示它抛出"$ is not defined"并将$更改为jquery会产生"jquery未定义"......有人可以帮忙吗?