爲什麼我會收到此錯誤?jQuery/Javascript錯誤:myvar [i]未定義
jQuery(document).ready(function($){
$('.stuff').each(function(){
function thing(id, count){
this.id = id;
this.count = count;
}
var myvar = new Array();
myvar.push(new thing('one', '134'));
myvar.push(new thing('two', '225'));
$('a', this).click(function(event){
var i = $(this).attr('class'); // class is 'one', 'two' etc...
// myvar[i] appears undefined here! wtf?
});
});
});
你有一個額外的括號,它應該是'變種I = $(本).attr( 'class');'或者是一個錯字? – karim79 2011-04-04 00:49:42
它的錯字,錯誤仍然存在:( – Alex 2011-04-04 00:50:30
@can你可以打印我在console.log中的值或警告i值,它可能是錯誤的... – kobe 2011-04-04 00:56:58