本帖最后由 zyixing 于 2012-11-22 12:08:03 编辑

解决方案 »

  1.   

    function imgFix(widthRestriction,heightRestriction,InclassName){
     var allElements = document.getElementsByTagName('*')     
     for(var i = 0; i < allElements.length; i++){     
    if(allElements[i].className.indexOf(InclassName) >= 0){       
    var imgElements = allElements[i].getElementsByTagName('img');       
    for(var j=0; j < imgElements.length; j++){         
    if( imgElements[j].width > widthRestriction || imgElements[j].height > heightRestriction ){           
    if( imgElements[j].width > imgElements[j].height){             
    imgElements[j].height = imgElements[j].height*(widthRestriction/imgElements[j].width);             
    imgElements[j].width = widthRestriction;
    }else{             
    imgElements[j].width = imgElements[j].width*(heightRestriction/imgElements[j].height);             
    imgElements[j].height = heightRestriction;
    }        
    }                 
    if( imgElements[j].height < heightRestriction ){                   
    imgElements[j].style.paddingTop = ( heightRestriction -imgElements[j].height ) /2 + "px";                 
    }       
    } /*for j*/     
    }   
    }/*for i*/ }是要这样的吗?把相应的参数放的位置一变就可以了
      

  2.   

    我在后面这样写了为什么不执行imgFix(80,100,'.img_list')
      

  3.   

    imgFix(80,100,'.img_list') 
    多了一个.