复制代码代码如下:
<html>
<adal>
<script type = "text / javascript">
/ * 判断设备是否为 pc * /
fonction ispc () {
var userAgentInfo = Navigator.UserAgentnt;
var agents = new Array ("Android", "iPhone", "Symbianos", "Windows Phone", "iPad", "iPod");
var flag = true;
pour (var v = 0; v <agents.length; v ++) {
if (userAgentInfo.indexof (agents [v])> 0) {
Flag = false;
casser;
}
}
drapeau de retour;
}
/ * 调整图片大小 * /
fonction autoreSizeImage (maxwidth, maxheight, objimg) {
var img = new image ();
img.src = objimg.src;
var hratio;
var wratio;
rapport var = 1;
var w = img.width;
var h = img.height;
wratio = maxwidth / w;
hratio = maxheight / h;
if (maxwidth == 0 && maxheight == 0) {
Rapport = 1;
} else if (maxwidth == 0) {//
IF (HRATIO <1) RATIO = HRATIO;
} else if (maxheight == 0) {
if (wratio <1) ratio = wratio;
} else if (wratio <1 || hratio <1) {
Rapport = (wratio <= hratio? Wratio: hratio);
}
if (ratio <1) {
w = w * ratio;
Ratio h = H *;
}
objimg.height = h;
objimg.width = w;
}
/ * 设置不同设备的缩放策略 * /
fonction setImg (tagid, pcwidth, pcheight, appwidth, appheight) {
var tag = document.getElementById (tagid);
var images = tag.getElementsByTagName ("img");
pour (var i = 0; i <images.length; i ++) {
if (ispc) {
AutoReSizeImage (pcWidth, pCHEight, images [i]);
}autre{
AutoResizeImage (appwidth, appheight, images [i]);
}
}
}
window.onload = function () {
setImg ('iMgDiv', 300,0,300,0);
}
</cript>
</ 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>
</docy>
</html>