复制代码代码如下:
<html>
<Evista>
<script type = "text/javaScript">
/ * 判断设备是否为 PC */
función ispc () {
var userAgentInfo = Navigator.Useragent;
VAR Agents = New Array ("Android", "iPhone", "Symbianos", "Windows Phone", "iPad", "iPod");
var flag = true;
para (var v = 0; v <agents.length; v ++) {
if (userAgentInfo.Indexof (agentes [v])> 0) {
bandera = falso;
romper;
}
}
Bandera de regreso;
}
/ * 调整图片大小 */
función AutoresizeImage (MaxWidth, MaxHeight, Objimg) {
var img = nueva imagen ();
img.src = objimg.src;
var hratio;
var wratio;
relación var = 1;
var w = img.width;
var h = img.Height;
wratio = maxwidth / w;
hratio = maxheight / h;
if (maxwidth == 0 && maxheight == 0) {
Relación = 1;
} else if (maxwidth == 0) {//
if (hratio <1) relación = hratio;
} else if (maxHeight == 0) {
if (wratio <1) relación = wratio;
} else if (wratio <1 || hratio <1) {
Ratio = (wratio <= hratio? Wratio: hratio);
}
if (relación <1) {
W = W * Ratio;
h = h * relación;
}
objimg.Height = h;
objimg.width = w;
}
/ * 设置不同设备的缩放策略 */
function setImg (Tagid, PCWidth, Pcheight, AppWidth, AppHeight) {
var tag = document.getElementById (TagID);
var Images = tag.getElementsBytagName ("img");
para (var i = 0; i <images.length; i ++) {
if (ispc) {
AutoresizeImage (PCWIDTH, PCHEIGHT, Imágenes [i]);
}demás{
AutoresizeImage (AppWidth, AppHeight, Images [i]);
}
}
}
window.onload = function () {
setimg ('imgdiv', 300,0,300,0);
}
</script>
</ablo>
<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>