出于兼容性原因,您应该使用jQuery的内置版本。
您只需将其排队即可:
function theme_scripts() {
wp_enqueue_script(\'jquery\');
}
add_action(\'wp_enqueue_scripts\', \'theme_scripts\');
或者只是将其添加为脚本的依赖项:
function theme_scripts() {
wp_enqueue_script( \'my-script\', <PATH>, array(\'jquery\'), ... );
}
add_action(\'wp_enqueue_scripts\', \'theme_scripts\');
But then... 您必须记住,jQuery是在无冲突模式下运行的,因此在脚本中,您必须通过
jQuery 而不是
$. 因此,您的脚本应该如下所示:
jQuery(function ($) {
// here you can use $ sign to get jQuery, because of the param of function
$(\'a\').click(...); // so this will work OK
});
// but here you can\'t and you have to use jQuery
jQuery(\'a\').click(...); // this will work also
$(\'a\').click(...); // but this won\'t, because there is no $ accessible here