好吧,所以我有一個js對象聲明在我的js文件的頂部,並在底部我有一個功能,正在創建一個屬性並添加一個值,但是當我去控制檯日誌在不同的功能,則返回undefined,但如果我登錄整個對象時,它顯示了對象,並低於其價值的新特性新特性是代碼:JavaScript的對象屬性日誌undefined
$(document).ready(function(){
var allVars={};
contentJson();
bioPageClass();
//start bioPage code.
function bioPageClass(){
console.log(allVars.nums)
//allVars.bioContent=allVars.allContent.theComittee.bios;
allVars.timeTxt=allVars.allContent.theComittee.timeline;
mouseEx();
bioInfo(0);
$('#next').click(function(){
var itsindex = inkDot($('.dot').index($('.filled'))+1);
});
$('#pre').click(function(){
var itsindex2 = inkDot($('.dot').index($('.filled'))-1);
});
function inkDot(dots){
$('.dot').removeClass('filled');
var equalize = dots < 0 ? 0 : dots;
if(equalize <= $('.dot').length -1){
$('.dot:eq('+equalize+')').addClass('filled');
console.log('1st if '+equalize);
bioInfo(equalize);
}else{
equalize=0;
console.log('the else '+equalize);
$('.dot:eq('+equalize+')').addClass('filled');
bioInfo(equalize);
}
}
function mouseEx(){
$(".TLBtn").mouseover(function(){
if(!$(this).hasClass('clkd')){
$(this).addClass("timeROver");
}
}).mouseout(function(){
if(!$(this).hasClass('clkd')){
$(this).removeClass("timeROver");
}
});
$(".TLBtn").click(function(){
$(".TLBtn").removeClass('clkd timeROver');
$(this).addClass('clkd timeROver');
})
}
function timeLineInfo(){
}
function bioInfo(ix){
$('.bioCon').fadeOut(100, function(){
$('#bioImage > img').attr('src',bioContent[ix].image);
$('#bioName').html(allVars.bioContent[ix].name);
$('#bioTitle').html(allVars.bioContent[ix].title);
$('#bioDisc').html(allVars.bioContent[ix].details);
$('.bioCon').fadeIn();
});
}
}
//end bio page code.
//call content json.
function contentJson(){
$.getJSON("content.json", function(json){
allVars.allContent = json;
allVars.nums = 8000;
});
}
});
我錯在這裏做什麼,我???
如果你用'alert'替換'console.log',輸出是否正確? – 2012-01-12 17:39:58
適用於Chromium 18.0.997.0的我,可能是瀏覽器問題。 – JaredMcAteer 2012-01-12 17:40:31
給出的代碼工作正常。 – Esailija 2012-01-12 17:45:02