Jquery 向页面添加其他javascript时出现问题
我将这个脚本添加到一个带有附加js的页面,它是独立工作的,但现在它在firebug、newbie、thx中出现了错误,需要任何帮助Jquery 向页面添加其他javascript时出现问题,jquery,Jquery,我将这个脚本添加到一个带有附加js的页面,它是独立工作的,但现在它在firebug、newbie、thx中出现了错误,需要任何帮助 function slideSwitch() { var $active = $('#slideshow DIV.active'); if ( $active.length == 0 ) $active = $('#slideshow DIV:last'); // use this to pull the divs in the order they appea
function slideSwitch() {
var $active = $('#slideshow DIV.active');
if ( $active.length == 0 ) $active = $('#slideshow DIV:last');
// use this to pull the divs in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#slideshow DIV:first');
// uncomment below to pull the divs randomly
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length );
// var $next = $( $sibs[ rndNum ] );
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
错误消息是:
$(function() {
setInterval( "slideSwitch()", 5000 );
});
您是否确保新页面包含jquery
如果是这样,请逐段添加代码,以缩小问题发生的范围。让我知道发生了什么。看起来您正在使用,尽管您没有提及。你加载jQuery库了吗?该库还定义了一个
$()
函数。在javascript代码执行后加载jquery。那根本行不通。将javascript放在一个外部文件中,在jquery之后加载。原始页面到底是什么,添加了什么?您使用的是什么库?不要使用以$开头的变量,尤其是在使用框架的情况下,以避免混淆。我同意您不应该使用以$开头的变量…如果第126行是定义回调的位置,那么语法很好,问题一定在别处。也许发布你的整个文件,同时仔细检查你没有同时包含prototype和jquery
$ is not defined index.html()()index.html (line 126)
$(function() {