
JS获取图片大小问题 20
vardi=d.getElementsByTagName('img');vardiw=di[0].width;alert(diw);在IE下正常。在FF下无法获取。为什么...
var di = d.getElementsByTagName('img');
var diw = di[0].width;
alert(diw);
在IE下正常。在FF下无法获取。为什么? 展开
var diw = di[0].width;
alert(diw);
在IE下正常。在FF下无法获取。为什么? 展开
4个回答
展开全部
<?
$arr=getimagesize("images/album_01.gif");
echo $arr[3];
$strarr=explode("\"",$arr[3]);
echo $strarr[1];
?>
<HTML>
<HEAD>
<TITLE>演示图片等比例缩小</TITLE>
<script>
function Wa_SetImgAutoSize(img)
{
//var img=document.all.img1;//获取图片
var MaxWidth=200;//设置图片宽度界限
var MaxHeight=100;//设置图片高度界限
var HeightWidth=img.offsetHeight/img.offsetWidth;//设置高宽比
var WidthHeight=img.offsetWidth/img.offsetHeight;//设置宽高比
alert("test"+img.offsetHeight+img.fileSize);
if(img.offsetHeight>1) alert(img.offsetHeight);
if(img.readyState!="complete"){
return false;//确保图片完全加载
}
if(img.offsetWidth>MaxWidth){
img.width=MaxWidth;
img.height=MaxWidth*HeightWidth;
}
if(img.offsetHeight>MaxHeight){
img.height=MaxHeight;
img.width=MaxHeight*WidthHeight;
}
}
function CheckImg(img)
{
var message="";
var MaxWidth=1;//设置图片宽度界限
var MaxHeight=1;//设置图片高度界限
if(img.readyState!="complete"){
return false;//确保图片完全加载
}
if(img.offsetHeight>MaxHeight) message+="\r高度超额:"+img.offsetHeight;
if(img.offsetWidth>MaxWidth) message+="\r宽度超额:"+img.offsetWidth;
if(message!="") alert(message);
}
</script>
</HEAD>
<BODY>
<img src="images/frequency.gif" border=0 id="img1" onload="CheckImg(this);">
<br>
<input id=inp type="file" onpropertychange="img1.src=this.value;">
</BODY>
</HTML>
$arr=getimagesize("images/album_01.gif");
echo $arr[3];
$strarr=explode("\"",$arr[3]);
echo $strarr[1];
?>
<HTML>
<HEAD>
<TITLE>演示图片等比例缩小</TITLE>
<script>
function Wa_SetImgAutoSize(img)
{
//var img=document.all.img1;//获取图片
var MaxWidth=200;//设置图片宽度界限
var MaxHeight=100;//设置图片高度界限
var HeightWidth=img.offsetHeight/img.offsetWidth;//设置高宽比
var WidthHeight=img.offsetWidth/img.offsetHeight;//设置宽高比
alert("test"+img.offsetHeight+img.fileSize);
if(img.offsetHeight>1) alert(img.offsetHeight);
if(img.readyState!="complete"){
return false;//确保图片完全加载
}
if(img.offsetWidth>MaxWidth){
img.width=MaxWidth;
img.height=MaxWidth*HeightWidth;
}
if(img.offsetHeight>MaxHeight){
img.height=MaxHeight;
img.width=MaxHeight*WidthHeight;
}
}
function CheckImg(img)
{
var message="";
var MaxWidth=1;//设置图片宽度界限
var MaxHeight=1;//设置图片高度界限
if(img.readyState!="complete"){
return false;//确保图片完全加载
}
if(img.offsetHeight>MaxHeight) message+="\r高度超额:"+img.offsetHeight;
if(img.offsetWidth>MaxWidth) message+="\r宽度超额:"+img.offsetWidth;
if(message!="") alert(message);
}
</script>
</HEAD>
<BODY>
<img src="images/frequency.gif" border=0 id="img1" onload="CheckImg(this);">
<br>
<input id=inp type="file" onpropertychange="img1.src=this.value;">
</BODY>
</HTML>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
跟你测试了一下啊,我改了一个地方 应该用 document.getElementsByTagName("") , 因为IE的纠错能力比火狐强 有的地方IE跟火狐的语法不一样,这个应该注意一下呢。结果运行正常,请看如下的代码:
<script type="text/javascript">
function openwin() {
window.open ('../ch01/ex1.jsp', 'newWindow', 'height=100, width=400, toolbar =no, menubar=no,scrollbars=no, resizable=no, location=no, status=no ')
}
function t(){
alert('图片') ;
var di = document.getElementsByTagName("img");
var diw = di[0].width;
alert(diw);
}
</script>
</head>
<body onload="t();">
<img alt="图片" src="images/google.jpg">
<input type="button" name="but" value="跳转" onclick="openwin();"/>
</body>
<script type="text/javascript">
function openwin() {
window.open ('../ch01/ex1.jsp', 'newWindow', 'height=100, width=400, toolbar =no, menubar=no,scrollbars=no, resizable=no, location=no, status=no ')
}
function t(){
alert('图片') ;
var di = document.getElementsByTagName("img");
var diw = di[0].width;
alert(diw);
}
</script>
</head>
<body onload="t();">
<img alt="图片" src="images/google.jpg">
<input type="button" name="but" value="跳转" onclick="openwin();"/>
</body>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用img.style.width 试试看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用img.style.width 试试看
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询