wordpress + jquery语法错误

use*_*625 1 syntax wordpress jquery syntax-error

我在这里得到了这个代码......

<script type="text/javascript">
    $('document').ready(function() {
        alert($('.thickbox'));
    });
</script>
Run Code Online (Sandbox Code Playgroud)

我把这段代码放在底部的wordpress主题footer.php文件中.当我进入我的页面时,警报没有出现,我检查我的错误控制台并发现此错误

TypeError: $ is not a function  

$('document').ready(function() {
Run Code Online (Sandbox Code Playgroud)

是什么赋予了?我的jquery文件在标题中,所以这应该工作...或者是否有一种特定的方式将jquery放入wordpress?

JKi*_*rtz 6

Wordpress的打包jQuery默认为noConflict模式,使用jQuery('document')或包装你的代码

(function($) { 
    // Code that uses jQuery's $ can follow here.
})(jQuery);
Run Code Online (Sandbox Code Playgroud)

或者在你的文件准备就像这样:

jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
});
Run Code Online (Sandbox Code Playgroud)