返回列表 發帖
$('img').each(function(i,obj){
    if( $(obj).attr('alt') != 'Error' ){
        $(obj).css({'width':'100px'})
    }else{
        $(obj).hide()
    }
})

TOP

   
$('img') // 取得 IMG TAG  
each  //跑回圈
function i,obj //I 是INDEX  OBJ 是目前物件
   $(obj).attr('alt')  取得該物件的 ALT 屬性
關於你說的 READY 後才動作,要看你的選擇器怎麼寫

TOP

本帖最後由 Mesak 於 2011-3-16 10:18 編輯

ready 不是給 IMG這個標籤用的,你可以用 load

$('img').each 已經把網頁中所有的圖片跑過了,沒必要再跑一次,這樣做重複了 n! 次
$(function(){
        $('img').each(function(a,obj){  
                if( $(obj).attr('alt') !== 'Error' ){  
                        $(obj).attr('alt','ok') 
                }else{  
                        $(obj).hide()  
                } 
        })
})

TOP

如果你只針對 LOAD 完畢 的話
$('img').ready(function(){  
 if( $(this).attr('alt') !== 'Error' ){  
     $(this).attr('alt') = 'ok'   
 }else{  
     $(this).hide()  
 }
})
這樣就可以了

TOP

$('img').each(function(i,obj)(
$(obj).ready(function(){    
 if( $(this).attr('alt') !== 'Error' ){    
     $(this).attr('alt') = 'ok'     
 }else{    
     $(this).hide()    
 }  
})
})  
不太清楚你要什麻效果

可以詳細說出來嗎?

TOP

返回列表 回復 發帖