2014-02-12 58 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