修改下载的一个163edit编辑器,无法进行图片大小限制.特请教高手.请帮忙注释一下下面这段代码,并插入一段判断代码:如果图片宽度大于650,则令其等于650;如果小于650,则保持不变.
var sPhotos=document.getElementById('imagess').value;
if ((sPhotos!=null) && (sPhotos!="http://")){
format("InsertImage", sPhotos);
var f = window.frames["HtmlEditor"];
var aImage = f.document.getElementsByTagName("img");
for(var i=0; i<aImage.length;i++){
  if (aImage[i].src == sPhotos){
    aImage[i].style.width = "650px";
  }
}
}
}发现不能用下面代码:onload='javascript:if(this.width > 650) this.width=650'
所以不要用这个.先谢谢了.

解决方案 »

  1.   

    CSS应该不行的,因为这个只是限制网页中的一部分图片的,其它的图片不能入这个限制.CSS是限制所有图片了?
      

  2.   

    var sPhotos=document.getElementById('imagess').value;//获取imagess的值
        if ((sPhotos!=null) && (sPhotos!="http://")){//如果sPhotos不等于空并且不等于http://
            format("InsertImage", sPhotos);//调用format()函数
            var f = window.frames["HtmlEditor"];//定义iframe对象
    var aImage = f.document.getElementsByTagName("img");//定义iframe对象内的所有图片对象,返回的aImage应该是所有图片对象集合而成的一个数组
    for(var i=0; i<aImage.length;i++){//循环
      if (aImage[i].src == sPhotos){//如果(假设i=0)aImage中的第一个对象的src值等于sPhotos的值
        aImage[i].style.width = "650px";//就设置它的宽度为650px
      }
    }
        }
    }ps:onload='javascript:if(this.width > 650) this.width=650'当然不对了,this是一个对象,width是一个css属性,应该这样this.style.width
      

  3.   

    onload = 'if(this.clientWidth > 650) this.style.width = 650px'
      

  4.   


    我说的是在不用
    var sPhotos=document.getElementById('imagess').value;
        if ((sPhotos!=null) && (sPhotos!="http://")){
            format("InsertImage", sPhotos);
            var f = window.frames["HtmlEditor"];
    var aImage = f.document.getElementsByTagName("img");
    for(var i=0; i<aImage.length;i++){
      if (aImage[i].src == sPhotos){
        aImage[i].style.width = "650px";
      }
    }
        }
    }
    的时候都不能直接用
    onload='javascript:if(this.width > 650) this.width=650'