2011-12-18 72 views
1

您好,我在我的網站上遇到了jquery問題。它工作正常,直到我創建了一個使用jQuery的插件。我排隊的腳本:關於WordPress運行網站的jquery問題

wp_enqueue_style("nstdt","***/wp-content/plugins/***/css/nstdt.css"); 
wp_enqueue_style("pagecss","***/wp-content/plugins/***/css/jPaginator.css"); 
wp_enqueue_script("nstdt","***/wp-content/plugins/***/js/nstdt.js",array("jquery")); 
wp_enqueue_script("paginate","***/wp-content/plugins/***/js/jPaginator.js",array("jquery","jquery-ui-core","jquery-ui-slider")); 

*只是模糊的網站的網址。

nstdt.js是我寫的jQuery,而jPaginator.js是我上網的腳本。

ndtdt啓動與此:

jQuery.noConflict(); 
jQuery(document).ready(function($){ 

和jPaginator.js開始,如:

(function($) { 
$.fn.jPaginator = function(o) { 

本身有一個小腳本運行在所謂的header.php迂迴這個主題

<?php wp_enqueue_script('jquery'); ?> 
<script type="text/javascript"> 
var $j = jQuery.noConflict(); 

    $j(document).ready(function() { 
       var interval; 

這些是我得到的錯誤:

jQuery is not defined 
Line 7 

    You must use this plugin with a unique element 
    ***/wp-includes/js/jquery/jquery.js?ver=1.7.1 
    Line 2 

獨特的元素事情看起來似乎是從jPaginator一個錯誤,因爲這是在第一行代碼:

if (this.size() != 1) 
    $.error('You must use this plugin with a unique element'); 

所以我想知道如果任何人有任何想法。是的,我通過螢火蟲檢查網站和jquery加載,並且是第一件加載。沒有404錯誤。

回答

2

嘗試將<?php wp_enqueue_script('jquery'); ?>取出。 WordPress默認已經加載jQuery,你甚至不需要撥打jQuery.noConflict()

就直接進入jQuery(document).ready(function($){...

+0

我試圖採取這一行了以及沒有衝突,仍然存在問題 – Tempus35 2011-12-18 21:56:09

+0

你是如何解決它的? – Vigrond 2011-12-20 00:12:53

3

只是確保jQuery選擇您用來初始化插件僅包含一個元素

例如:

// where #test1 is unique in your page 
$("#test1").jPaginator({ <your paramaters>}); 



// or for a list (ie : $(".myclass").length > 1) 
$(".myclass").each(function() { 
    $(this).jPaginator({ <your paramaters>}); 
});