}
function dxy_ReImgSize(){
var box=$("dxy_content");
var imgall=box.getElementsByTagName("img")
for (i=0;i<imgall.length;i++)
{
if (imgall[i].width>500)
{
var oWidth=imgall[i].width;
var oHeight=imgall[i].height;
imgall[i].width="500";
imgall[i].height=oHeight*500/oWidth;
}
}
}
可又发现,如果低浏览器,不支持getElementsByTagName,就没的玩了,好处是可以控制区域.
最后没办法了,就先弄个,暂时的解决办法
function ReImgSize(){
for (i=0;i<document.images.length;i++)
{
if (document.all){
if (document.images[i].width>500)
{
var oWidth=document.images[i].width;
var oHeight=document.images[i].height;
document.images[i].width="500";
document.images[i].height=oHeight*500/oWidth;
document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>'
}
}
else{
if (document.images[i].width>500) {
var oWidth=document.images[i].width;
var oHeight=document.images[i].height;
document.images[i].width="500";
document.images[i].height=oHeight*500/oWidth;
document.images[i].title="在新窗口打开图片";
document.images[i].style.cursor="pointer"
document.images[i].onclick=function(e){window.open(this.src)}
}
}
}
}
注意我增加了
var oWidth=document.images[i].width;
var oHeight=document.images[i].height;
document.images[i].width="500";
document.images[i].height=oHeight*500/oWidth;
如果大家发现了什么更好的方法,贴出来啊
www.jb51.net 易采站长站 原创,转载请写明出处










