简体   繁体   English

jQuery在Wordpress中不起作用-默认工作

[英]jQuery not working in Wordpress - Works on default

This little snippet here works just fine in JSFiddle, but it does nothing when I put it in with the tabs within a PHP file for a WordPress button. 这个小片段在JSFiddle中可以正常工作,但是当我将它与WordPress按钮的PHP文件中的选项卡放在一起时,它什么也没做。 I currently have standard JavaScript on it to open a popup dialog with "Ok" & "Cancel" but I'd like to use "Yes", "No" & "Cancel" instead. 我目前使用标准的JavaScript来打开带有“确定”和“取消”的弹出对话框,但我想改用“是”,“否”和“取消”。

What's the issue here? 这里有什么问题?

http://jsfiddle.net/vvjj8/617/ http://jsfiddle.net/vvjj8/617/

HTML 的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 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);

Errors 失误

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

What cpilko said is valid, but if you prefer to use the $ variable in your code (it can be easier for multiple reasons) then redefine it when you call your jquery like so: cpilko所说的是有效的,但是如果您更喜欢在代码中使用$变量(由于多种原因可能更容易),则在调用jquery时重新定义它,如下所示:

<script>
 jQuery(document).ready(function($) {

  // you can now use the $ variable
  $("#dialog-confirm").html("Do you have Play WithSix installed?");

 )};

</script>

Wordpress uses jQuery noconflict mode . WordPress使用jQuery noconflict模式 Try replacing all the $ in your code with jQuery . 尝试用jQuery替换代码中的所有$

function fnOpenNormalDialog() {
  jQuery("#dialog-confirm").html("Do you have Play WithSix installed?");
  ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM