复制代码代码如下:
<html>
<head>
<script type = "text/javascript">
/ *判断设备是否为PC */
関数ISPC(){
var useragentinfo = navigator.useragent;
var Agents = new Array( "Android"、 "iPhone"、 "Symbianos"、 "Windows Phone"、 "iPad"、 "iPod");
var flag = true;
for(var v = 0; v <agents.length; v ++){
if(useragentinfo.indexof(agents [v])> 0){
flag = false;
壊す;
}
}
フラグを返します。
}
/ *调整图片大小 */
function autoresizeImage(maxwidth、maxheight、objimg){
var img = new Image();
img.src = objimg.src;
var hratio;
var wratio;
var比= 1;
var w = img.width;
var h = img.height;
wratio = maxwidth / w;
hratio = maxheight / h;
if(maxwidth == 0 && maxheight == 0){
比率= 1;
} else if(maxwidth == 0){//
if(hratio <1)比= hratio;
} else if(maxheight == 0){
if(wratio <1)比= wratio;
} else if(wratio <1 || hratio <1){
比率=(wratio <= hratio?wratio:hratio);
}
if(比率<1){
w = w *比。
H = H *比。
}
objimg.height = h;
objimg.width = w;
}
/ *设置不同设备的缩放策略 */
function setimg(tagid、pcwidth、pcheight、appwidth、appheight){
var tag = document.getElementById(tagid);
var images = tag.getelementsbytagname( "img");
for(var i = 0; i <images.length; i ++){
if(ispc){
autoresizeImage(pcwidth、pcheight、images [i]);
}それ以外{
autoresizeImage(appwidth、appheight、images [i]);
}
}
}
window.onload = function(){
setimg( 'imgdiv'、300,0,300,0);
}
</script>
</head>
<body>
<div id = "imgdiv">
<img src = "http://192.168.1.116:9999/ffzx/news/20140205/015212022_1.jpg"/>
<div>
<img src = "http://192.168.1.116:9999/ffzx/news/20140208/1386835169183.jpg"/>
</div>
</div>
<br>
</body>
</html>