这里的这个小片段在JSFiddle中运行得很好,但当我将它与WordPress按钮的PHP文件中的选项卡放在一起时,它什么也没用。我目前有标准的JavaScript在上面打开一个弹出对话框"Ok"&"取消",但我想使用"是"、"否"&改为"取消"。
这里有什么问题?
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?");
...