谁帮我看看这段代码应该怎么弄 本帖最后由 zyixing 于 2012-11-22 12:08:03 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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*/ }是要这样的吗?把相应的参数放的位置一变就可以了 我在后面这样写了为什么不执行imgFix(80,100,'.img_list') imgFix(80,100,'.img_list') 多了一个. javascript求解释```` Ext 加载分页问题? ajax 回调成功后 回调函数执行出错 大家帮忙看看 急 急,大家帮忙看看在FirFox下要点两下才能弹出层 如何点右键插入当前系统日期? JS问题,请大家帮忙? 求教,这个代码是什么意思? 我想在正则表达式中,只允许用户输入“!&%”这三种字符,除了这三个之外不允许通过,多谢了 不同窗口传值问题? 高手才能解决的问题. linux服务器上<option>标签的点击事件没有效果,window上本地测试有,求原因? 一个关于undefined的问题
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*/ }是要这样的吗?把相应的参数放的位置一变就可以了
多了一个.