function imgFix() { 
  //定义要限制的图片宽高,这个宽高要同style里面定义的相同，小于限定高宽的图片不操作 
  var widthRestriction = 750; 
  var heightRestriction = 6000; 
  var width = 310; 
  var height = 310; 
  var allElements = document.getElementsByTagName('*')   
  for (var i = 0; i < allElements.length; i++) 
  { 
    if (allElements[i].className.indexOf('detail') >= 0) //indexof('class名称')
        { 
      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; 
          } 
        } 
      } /*for j*/ 
    } 

   if (allElements[i].className.indexOf('pho_m') >= 0) //indexof('class名称')
        { 
      var imgElements = allElements[i].getElementsByTagName('img'); 
      for (var j=0; j < imgElements.length; j++) 
          { 
        if ( imgElements[j].width > width || imgElements[j].height > height ) 
                { 
          if ( imgElements[j].width > imgElements[j].height) 
                  { 
            imgElements[j].height = imgElements[j].height*(width/imgElements[j].width); 
            imgElements[j].width = width; 
          } else 
                  { 
            imgElements[j].width = imgElements[j].width*(height/imgElements[j].height); 
            imgElements[j].height = height; 
          } 
        } 
                if ( imgElements[j].height < height ) 
                { 
                  imgElements[j].style.paddingTop = ( height -imgElements[j].height ) /2 + "px"; 
                } 
      } /*for j*/ 
    } 
  }/*for i*/ 
} 
window.onload = imgFix; 