[英]Uncaught TypeError: undefined is not a function when using a jQuery plugin in Magento
[英]jQuery “Uncaught TypeError: undefined is not a function” when using fadeIn();
我是JS的新手,我正在為同一文檔中的每個頁面編寫一個基本的jQuery豐富的網頁,其淡入/淡出(使用具有單獨ID的相同div元素)。 無論如何,當我嘗試淡入當前頁面時,我收到錯誤“Uncaught TypeError:undefined is not a function”,我在網上搜索但找不到解決方案。
HTML在腳本之前加載,並且完整的jQuery庫已包含在頁面的標題中。
我定位的div元素有“display:none;” 在我的CSS中設置。
HTML
<div class="page_content" id="page_home">
Content removed
</div>
JS:
<script>
var cp = "page_home";
var tp = document.getElementById(cp);
tp.fadeIn('slow');
</script>
有經驗的人有什么相似的解決方案嗎? 我確信它很簡單,因為我的代碼無論如何......
tp
是一個簡單的javascript對象,它沒有一個名為.fadeIn()
的函數
嘗試將其包裝在$()
以使其成為jquery對象然后執行,
$(tp).fadeIn('slow');
或者更好地使用jquery的id selector
來獲取元素,
$("#page_home").fadeIn('slow');
因為tp
不是jquery對象,所以它不會有與jquery相關的方法。
使用,
$("#page_home").fadeIn('slow');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.