本文介绍了jQuery“Uncaught TypeError:undefined不是函数”当使用fadeIn();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JS的新手,我正在为同一文档中的每个页面编写一个基本的jQuery丰富的网页,其淡入/淡出(使用具有单独ID的相同div元素)。无论如何,当我尝试淡入当前页面时,我收到错误Uncaught TypeError:undefined is not a function,我在网上搜索但找不到解决方案。

I am new to JS and I am writing a basic jQuery-rich webpage with fade-in/fade-out for each page in the same document (using the same div element with separate IDs). Anyway, when I try to fade in the current page, I receive the error "Uncaught TypeError: undefined is not a function", I've had a search around online but couldn't find a solution.

在脚本之前加载HTML并且页面标题中包含完整的jQuery库。

The HTML is loaded before the script and the full jQuery library has been included in the header of the page.

div元素我是定位有display:none;在我的CSS中设置。

The div element I am targeting has "display: none;" set in my 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>

任何人都有类似的经历并有解决方案吗?我确信这很简单,因为我的代码无论如何......

Anyone experienced anything similar and have a solution? I'm sure it's something simple, since my code is anyway...

推荐答案

tp 是一个简单的javascript对象,它没有一个名为的函数.fadeIn()

tp is a plain javascript object and it does not has a function called .fadeIn()

尝试将其包装在 $()中以使其成为jquery对象然后执行,

Try to wrap it inside $() to make it a jquery object then do,

$(tp).fadeIn('slow');

或者更好地使用jquery的获取元素,

or better use jquery's id selector to grab the element,

$("#page_home").fadeIn('slow');

这篇关于jQuery“Uncaught TypeError:undefined不是函数”当使用fadeIn();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:43