日期:2014-05-16 浏览次数:20336 次
<img id="imgPro" runat="server" class="imgInfo" /> .imgInfo { max-width:365px; width:expression(document.body.clientWidth>365?"365px":"auto"); overflow:hidden; }
this.imgPro.Attributes.Add("onload", "changeImg(this)");//有时可以控制,有时图片就原样显示,必须刷新几次才行
<script language="javascript" type="text/javascript">
<!--
function changeImg(mypic){
var xw=365;
var width = mypic.width;
var height = mypic.height;
var bili = width/height;
var A=width/xw;
if(A>1)
{
mypic.width=xw;
mypic.height=xw/bili;
}
}
//-->
</script>
this.imgPro.Attributes.Add("onload", "javascript:if (this.width>365) this.width=365;");
function ImgW(ImgID,Width){ var obj = document.getElementById(ImgID); if(obj != null) { var w = obj.width; var h = obj.height; if (w > Width){ obj.width = Width; obj.height = h*Width/w; } } }; ImgW("aa" ,"365");
------解决方案--------------------
function ImgW(ImgID,Width){
var obj = document.getElementById(ImgID);
if(obj != null)
{
var w = obj.width;
var h = obj.height;
if (w > Width){
obj.width = Width;
obj.height = h*Width/w;
}
}
};
ImgW("aa" ,"365");
------解决方案--------------------
嘿嘿~~~1楼正解
不过如果考虑执行顺序,应该
function ImgW(ImgID,Width){ var obj = document.getElementById(ImgID); if(obj != null) { var w = obj.width; var h = obj.height; if (w > Width){ obj.width = Width; obj.height = h*Width/w; } } }; window.onload=function() { ImgW("aa" ,"365"); }