复制代码代码如下:
<html>
<head>
<script type = "text/javascript">
/ * 判断设备是否为 pc */
função ispc () {
var userAgentInfo = Navigator.UserAgent;
var agentes = new Array ("Android", "iPhone", "Symbianos", "Windows Phone", "iPad", "iPod");
var flag = true;
for (var v = 0; v <agents.length; v ++) {
if (userAgentInfo.indexof (agentes [v])> 0) {
bandeira = false;
quebrar;
}
}
bandeira de retorno;
}
/ * 调整图片大小 */
Função AutoresizeImage (MaxWidth, MaxHeight, Objimg) {
var iMg = new Image ();
img.src = objimg.src;
var hratio;
var wratio;
Proporção var = 1;
var w = img.width;
var H = img.Height;
wratio = maxwidth / w;
hratio = maxHeight / h;
if (maxwidth == 0 && maxHeight == 0) {
Razão = 1;
} else if (maxwidth == 0) {//
IF (hratio <1) razão = hratio;
} else if (maxHeight == 0) {
if (wratio <1) ratio = wratio;
} else if (wratio <1 || hratio <1) {
Razão = (wratio <= hratio? Wratio: hratio);
}
if (proporção <1) {
W = W * proporção;
H = H *.
}
objimg.Height = h;
objimg.width = w;
}
/ * 设置不同设备的缩放策略 */
Função setImg (TAGID, PCWidth, PCHeight, AppWidth, AppHeight) {
var tag = document.getElementById (TAGID);
var imagens = tag.getElementsByTagName ("img");
for (var i = 0; i <imagens.length; i ++) {
if (iSPC) {
AutoresizeImage (PCWidth, PCHeight, imagens [i]);
}outro{
AutoresizeImage (AppWidth, AppHeight, imagens [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>