var t=new Array('title','placeholder','alt');
$.each(t,function(k,v){
alert(typeof $(this).attr(v));//PROBLEM $(this) is not the right object
});
目標:存在獲取屬性的(標題或佔位符或ALT)值。jQuery的GET ATTR值
如果元素有標題,則返回標題,如果沒有,則選中佔位符,然後alt。
例如:
>> var v='title';
>> $(this).attr(v);
>> $(this).attr('title');(I want this)
舊SOLUTION:
for(var i=0;i<t.length;i++){
alert($(this).attr(t[i]));
}
真正的解決方案:(由於mplungjan)
var o=$(this);
$.each(t,function(k,v){
alert(typeof o.attr(v));//PROBLEM $(this) is not the right object
});
因爲在數組沒有ATTR和v不是一個jQuery對象 - '警告(typeof運算V);' – mplungjan