2014-09-06 91 views
0

我在下面附加的代碼似乎在做他的事情,但是當我將它包含在我的WordPress站點中時,它就不起作用。那麼有什麼特別的,我應該做的正確包括它?我甚至試圖通過wp_register/enqueue_script添加它,但我還是什麼也沒得到:SjQuery onclick在Wordpress中顯示/隱藏框

下面的代碼:

<style> 
#drop { 
    display: none; 
} 
</style> 

<script> 
$(document).ready(function(){ 
    $('#trigger').click(function(event){ 
     event.stopPropagation(); 
     $('#drop').toggle(); 
    }); 
    $(document).click(function(){ 
     $('#drop').hide(); 
    }); 
}); 
</script> 

<div class="wrapper"> 
    <a id="trigger" href="#">Click Me</a> 
    <div id="drop">Content</div> 
</div> 

jsfiddle

任何想法?在此先感謝:)

回答

0

當點擊觸發器時顯示。

$(document).ready(function(){ 
    $('#trigger').click(function(event){ 
     $('#drop').show(); 
    }); 
    $(document).click(function(){ 
     $('#drop').hide(); 
    }); 
}); 
0

沒有衝突模式?

var j = jQuery.noConflict(); 

// Do something with jQuery 
j("div p").hide(); // instead $("div p").hide(); 
0

我很抱歉,夥計們。我很感謝你的努力,寫這篇文章時我感覺很蠢,但這是一個極其簡單的錯誤。我在WordPress的提供了jQuery noConflict包裝的一個封閉的:

(function($) { 
    // Inside of this function, $() will work as an alias for jQuery() 
    // and other libraries also using $ will not be accessible under this shortcut 
})(jQuery); 

我搞混了一些其他功能和錯誤我刪除了這個功能,我試圖制定出結束括號。

對此深表歉意。 <