2014-02-12 55 views
-3

我有以下的jQuery功能:更改「jQuery的」功能「的jQuery WordPress的」功能

function lookup(inputString, divid, filename) { 
    if(inputString.length == 0) { 
     $('#'+divid).fadeOut(); // Hide the suggestions box 
    } else { 
     if (inputString.length > 2) { 
      $.post(filename, {queryString: ""+inputString+""}, function(data) { // Do an AJAX call 
      $('#'+divid).fadeIn(); // Show the suggestions box 
      $('#'+divid).html(data); // Fill the suggestions box 
      }); 
     } 
    } 
} 

它的工作很好,但我想在wordpress主題來使用它。任何想法如何改變功能,它可以用於wordpress?

+0

爲什麼它不能在Wordperss中工作?只要確保你在Wordpress中包含JQuery ... – randomizer

+0

它不是一個「jQuery」函數,它是一個使用jQuery庫的「JavaScript」函數。 – Cerbrus

+0

這個問題不是「太寬泛」。第一個答案是正確的解決方案,所以它很好... – user1136199

回答

2

通常情況下,jQuery的是因爲這兩個WordPress的使用$衝突,你可以嘗試在你的代碼改變$jQuery

function lookup(inputString, divid, filename) { 
    if(inputString.length == 0) { 
     jQuery('#'+divid).fadeOut(); // Hide the suggestions box 
    } else { 
     if (inputString.length > 2) { 
      jQuery.post(filename, {queryString: ""+inputString+""}, function(data) { // Do an AJAX call 
      jQuery('#'+divid).fadeIn(); // Show the suggestions box 
      jQuery('#'+divid).html(data); // Fill the suggestions box 
      }); 
     } 
    } 
} 
+0

thx的答案。必須更改我的所有腳本;-)將其儘快標記爲答案! – user1136199