Javascript jquery在wordpress中不工作
Wordpress没有加载jquery——我认为这可能与它加载文件是绝对的,而不是相对的,并且它不会转到url(firebug说拒绝访问受限uri)有关。我已经测试了vanilla javascript,它可以工作,但是只要我尝试在Javascript jquery在wordpress中不工作,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,Wordpress没有加载jquery——我认为这可能与它加载文件是绝对的,而不是相对的,并且它不会转到url(firebug说拒绝访问受限uri)有关。我已经测试了vanilla javascript,它可以工作,但是只要我尝试在$(document.ready(function(){})中执行最基本的函数,它就会停止工作。。有没有办法阻止wordpress将网站uri附加到链接的文件中,并相对地引用它们,因为我认为这可能会解决这个问题 输出的磁头如下所示: <!DOCTYPE html
$(document.ready(function(){})
中执行最基本的函数,它就会停止工作。。有没有办法阻止wordpress将网站uri附加到链接的文件中,并相对地引用它们,因为我认为这可能会解决这个问题
输出的磁头如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>simplespace — not quite ready yet</title>
<meta name="generator" content="WordPress 3.0.1" /> <!-- leave this for stats -->
<link rel="stylesheet" href="http://simplespace.co.nz/wp-content/themes/blass2/style.css" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://simplespace.co.nz/feed/" />
<link rel="alternate" type="text/xml" title="RSS .92" href="http://simplespace.co.nz/feed/rss/" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="http://simplespace.co.nz/feed/atom/" />
<link rel="pingback" href="http://simplespace.co.nz/xmlrpc.php" />
<link rel="shortcut icon" href="http://simplespace.co.nz/wp-content/themes/blass2/favicon.ico" />
<link rel='archives' title='September 2010' href='http://simplespace.co.nz/2010/09/' />
<link rel='stylesheet' id='sociable3-css' href='http://simplespace.co.nz/wp-content/plugins/sociable-30/sociable.css?ver=5.10' type='text/css' media='all' />
<script type='text/javascript' src='http://simplespace.co.nz/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
<script type='text/javascript' src='http://simplespace.co.nz/wp-content/plugins/wordpress-flickr-manager/js/jquery.lightbox.js?ver=3.0.1'></script>
<script type='text/javascript' src='http://simplespace.co.nz/wp-content/plugins/wordpress-flickr-manager/js/wfm-lightbox.php?ver=3.0.1'></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://simplespace.co.nz/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://simplespace.co.nz/wp-includes/wlwmanifest.xml" />
<link rel='index' title='simplespace' href='http://simplespace.co.nz/' />
<meta name="generator" content="WordPress 3.0.1" />
<script type="text/javascript" src="http://simplespace.co.nz/wp-content/plugins/audio-player/assets/audio-player.js?ver=2.0.4.1"></script>
<script type="text/javascript">AudioPlayer.setup("http://simplespace.co.nz/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1", {width:"400",animation:"yes",encode:"yes",initialvolume:"60",remaining:"no",noinfo:"no",buffer:"5",checkpolicy:"no",rtl:"no",bg:"dcf2fa",text:"333333",leftbg:"dcf2fa",lefticon:"333333",volslider:"666666",voltrack:"cfcfcf",rightbg:"9ee1f7",rightbghover:"dcf2fa",righticon:"333333",righticonhover:"333333",track:"FFFFFF",loader:"9ee1f7",border:"CCCCCC",tracker:"dcf2fa",skip:"666666",pagebg:"FFFFFF",transparentpagebg:"yes"});</script>
<!-- WFM INSERT LIGHTBOX FILES -->
<link rel="stylesheet" href="http://simplespace.co.nz/wp-content/plugins/wordpress-flickr-manager/css/lightbox.css" type="text/css" />
<!-- WFM END INSERT -->
<script type='text/javascript'>
$(document).ready(function() {
alert('test');
});
</script>
</head>
simplespace&mdash;还没准备好
AudioPlayer.setup(“http://simplespace.co.nz/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1“,{宽度:“400”,动画:“是”,编码:“是”,初始音量:“60”,剩余:“否”,noinfo:“否”,缓冲区:“5”,检查策略:“否”,rtl:“否”,背景:“dcf2fa”,文本:“333333”,左bg:“dcf2fa”,左图标:“333333”,volslider:“666666”,voltrack:“cfcfcf”,右bg:“9ee1f7”,右键悬停:“dcf2fa”,右键图标:“333333”,右键悬停:“333333”,轨迹:“FFFFFF”,加载器:“9ee1f7”,边框:“CCCCCC”,跟踪器:“dcf2fa”,跳过:“666666”,页面背景:“FFFFFF”,透明页面背景:“是”});
$(文档).ready(函数(){
警报(“测试”);
});
Wordpress将jQuery置于无冲突模式,从而禁用了$()
功能。除非在jQuery中禁用无冲突模式,否则必须使用jQuery()
而不是$()
我查看了站点,jQuery正在加载。这:
<script type='text/javascript'>
$(document).ready(function() {
alert('test');
});
</script>
是在无冲突模式下调用它的方式。lightbox插件也抛出了一个错误:
未捕获类型错误:对象#没有方法“lightBox”请尝试以下操作:
为那些面临同样问题的人提供完整答案
您可以将javascript
封装在一个自调用函数中,然后将jQuery
作为参数传递给它,使用$
作为局部变量名。例如:
(function($) {
$(document).ready(function(){
alert('test');
});
}(jQuery));
WordPress附带的jQuery
库设置为noConflict()
模式。这是为了防止与WordPress可以链接的其他JavaScript库的兼容性问题
在
noConflict()
模式下,jQuery的全局$
快捷方式不可用。请在中添加您现在拥有的内容。看起来您可能没有在$(document.ready(function(){})之前的头文件中包含jquery文件
(function($) {
$(document).ready(function(){
alert('test');
});
}(jQuery));