[英]JQuery that works in a JSfiddle not working on a WordPress site
[英]jQuery not working in Wordpress - Works on default
这个小片段在JSFiddle中可以正常工作,但是当我将它与WordPress按钮的PHP文件中的选项卡放在一起时,它什么也没做。 我目前使用标准的JavaScript来打开带有“确定”和“取消”的弹出对话框,但我想改用“是”,“否”和“取消”。
这里有什么问题?
http://jsfiddle.net/vvjj8/617/
的HTML
<li class="level3 item578"><a id="btnOpenDialog" value="Confirm Dialog Box" href="#"><span>ArmA 2</span></a>
</li>
<div id="dialog-confirm"></div>
jQuery的
function fnOpenNormalDialog() {
$("#dialog-confirm").html("Do you have Play WithSix installed?");
// Define the Dialog and its properties.
$("#dialog-confirm").dialog({
resizable: false,
modal: true,
title: "ArmA 2",
height: 250,
width: 360,
buttons: {
"Yes": function () {
$(this).dialog('close');
window.location.href = "http://www.fogamers.com/arma2.php";
},
"No": function () {
$(this).dialog('close');
window.open('http://play.withsix.com/', '_blank');
},
"Cancel": function () {
$(this).dialog('close');
}
}
});
}
$('#btnOpenDialog').click(fnOpenNormalDialog);
失误
Uncaught TypeError: undefined is not a function (index):76
(anonymous function) (index):76
f.event.dispatch jquery.min.js:3
h.handle.i
Uncaught TypeError: undefined is not a function widgetkit-dd62f244.js:13
(anonymous function) widgetkit-dd62f244.js:13
o jquery.js?ver=1.7.2:2
p.fireWith jquery.js?ver=1.7.2:2
w jquery.js?ver=1.7.2:4
d
Uncaught TypeError: undefined is not a function (index):203
(anonymous function) (index):203
o jquery.min.js:2
p.fireWith jquery.min.js:2
e.extend.ready jquery.min.js:2
c.addEventListener.B
cpilko所说的是有效的,但是如果您更喜欢在代码中使用$
变量(由于多种原因可能更容易),则在调用jquery时重新定义它,如下所示:
<script>
jQuery(document).ready(function($) {
// you can now use the $ variable
$("#dialog-confirm").html("Do you have Play WithSix installed?");
)};
</script>
WordPress使用jQuery noconflict模式 。 尝试用jQuery
替换代码中的所有$
。
function fnOpenNormalDialog() {
jQuery("#dialog-confirm").html("Do you have Play WithSix installed?");
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.