复制代码代码如下 :
<html>
<헤드>
<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;
부서지다;
}
}
리턴 플래그;
}
/ * 调整图片大小 */
함수 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;
}
/ * 设置不同设备的缩放策略 */
함수 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, 이미지 [i]);
}또 다른{
AutoresizeImage (AppWidth, AppHeight, 이미지 [i]);
}
}
}
Window.onload = function () {
setimg ( 'imgdiv', 300,0,300,0);
}
</스크립트>
</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>