我正在尝试制作一个简单的函数来onclick="changeYoutube('XXXXXX');"
在链接标签中调用时替换 ATTR。然而,目前说调用“changeYoutube”会引发“未捕获的 ReferenceError:changeYoutube 未定义”错误。
function changeYoutube(source) {
$('#youtube-viewport').attr('src', 'http://www.youtube.com/embed/' + source);
}
整个 JS 核心
// Control Header Size
$(window).load(function() {
var imageGrad = $('.image-grad'),
image = $('#header-image-border img'),
border = $('#header-image-border'),
grad = $('#header-image-grad');
function resizeDiv () {
imageGrad.height(image.height());
imageGrad.width($(window).width());
border.css({'height': + image.height()});
}
resizeDiv();
$(window).resize(function() { resizeDiv(); });
});
$(document).ready(function() {
// Content Parser
var contentQuery = './content.php';
$('#background-overlay').fadeTo(1200, 1.0, function() {
// Body loaded...
$('#hi1').fadeTo(2000, 1.0, function() {
// Start Slides
var slide = 0,
ids = [
'#hi1',
'#hi2',
'#hi3',
'#hi4'
],
count = ids.length;
slideShow = setInterval(function () {
var nextSlide = slide + 1;
if (nextSlide > count - 1) {
nextSlide = 0;
}
$(ids[slide]).fadeTo(600, 0);
$(ids[nextSlide]).fadeTo(2300, 1.0);
slide++;
if (slide > count - 1) {
slide = 0;
}
}, 20000);
// End Slides
// Slide Header Bar
$('#header-container').slideToggle('slow', function() {
// Load Containers
$('#boxes-container').fadeTo(1200, 1.0);
$('#footer-content').fadeTo(1200, 1.0);
// FadeIn Header Bar
$('#header').fadeTo('slow', 1.0, function() {
// Header loaded... start navigation load n' stuff
$('.logo').fadeTo(3000, 0.60, function() {
$('#icons-container img:first').fadeIn();
// Start Slides
var currentImage = $('#icons-container img:first');
setInterval(function(){
currentImage.fadeOut();
if(currentImage.next().size())
currentImage = currentImage.next();
else
currentImage = currentImage.siblings().first();
currentImage.fadeIn();
}, 5000);
// End Slides
});
$('#drop-ucp').slideToggle('slow');
(function fadeLink($){
$.eq(0).fadeTo(400, 0.50, function(){
($=$.slice(1)).length && fadeLink($);
});
})($('#navigation-list > li'));
});
});
});
});
$('#navigation-list li').mouseenter(function(){
$(this).fadeTo('slow', 1.0);
});
$('#navigation-list li').mouseout(function(){
$(this).fadeTo('fast', 0.60);
})
$('.logo').mouseenter(function(){
$(this).fadeTo('slow', 1.0);
});
$('.logo').mouseout(function(){
$(this).fadeTo('fast', 0.60);
});
$('.search').click(function() {
$('.search').val('');
});
$('.search').blur(function() {
$('.search').val('Track Title / Game Title');
});
// Youtube Control
function changeYoutube(source) {
$('#youtube-viewport').attr('src', 'http://www.youtube.com/embed/' + source);
}
});