图片自适应宽度和高度的问题 1.可以用 document.getElementsByTagName("img")获取到所有的img对象2.在遍历每一个对象,来指定它的宽和高 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script language="javascript"> var flag=false; function DrawImage(ImgD){ var image=new Image(); image.src=ImgD.src; if(image.width>0 && image.height>0){ flag=true; if(image.width/image.height>=290/240){ if(image.width>290){ ImgD.width=290; ImgD.height=(image.height*290)/image.width; }else{ ImgD.width=image.width; ImgD.height=image.height; } } else{ if(image.height>280){ ImgD.height=280; ImgD.width=(image.width*280)/image.height; }else{ ImgD.width=image.width; ImgD.height=image.height; } } } } function Init() { var obj=document.getElementsByTagName("img"); for (var j=0; j < obj.length; j++) { DrawImage(obj[j]); }}window.onload=Init;</script> <body><img src="../images/ybfq_1.jpg" alt="0" width="500" height="261" /><img src="../images/ybfq_2.jpg" alt="0" width="757" height="234" />不用理会$str里的.直接读取所以图片. php也可以处理图片自适应的啊~ 楼上的都答完了。用document.getElementsByTagName("img")遍历是正解。不用动$str. 引用:楼上的都答完了。用document.getElementsByTagName("img")遍历是正解。不用动$str.如果页面中有很多图片,但只有从$str里出来的图片才想自适应,则可对$str里的<img />内容加点特殊内容,当然这样做的话就可以直接来处理$str就行了,不在浏览器端动用JS了 php代码里面怎么调用html里面的一部分代码? php在mysql中插入的问题!!! 高手过来看下,求如下代码 英文sql可以执行 但是有汉字失败 为什么有些地方可以用$_POST[var]来防问变量,而有些机器只能通过$_POST['var']来防问呢? PHP 中关于switch语句的疑问 我不能浏览回复帖子了。 为什么我不能得到POST表单提交过的数据? edit plus每次打开文件后都留下一个bak文件,怎么不要呢 请问打侠们,php是否有进行加密解密的软件 有关多个checkbox的与数据库中数据关联的问题 用php+smarty开发了一个B2B简易程序,大家帮忙测试
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>=290/240){
if(image.width>290){
ImgD.width=290;
ImgD.height=(image.height*290)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>280){
ImgD.height=280;
ImgD.width=(image.width*280)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
function Init() {
var obj=document.getElementsByTagName("img");
for (var j=0; j < obj.length; j++) {
DrawImage(obj[j]);
}
}
window.onload=Init;
</script>
<body>
<img src="../images/ybfq_1.jpg" alt="0" width="500" height="261" />
<img src="../images/ybfq_2.jpg" alt="0" width="757" height="234" />不用理会$str里的.直接读取所以图片.
引用:
楼上的都答完了。用document.getElementsByTagName("img")遍历是正解。不用动$str.如果页面中有很多图片,但只有从$str里出来的图片才想自适应,则可对$str里的<img />内容加点特殊内容,当然这样做的话就可以直接来处理$str就行了,不在浏览器端动用JS了