探讨一个使用JS显示图片的问题 没用过你这种方法创建图片。我都是直接用document.creatElement("IMG")或者document.write("<img></img>")的方式 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 “通过alert()来查看每次返回图片的宽度值,可有时候返回的值是0。”==》因为图片还没有加载完毕,所以返回值为0可以先通过readystate判断图片是否已经加载完成,然后再取width;<html><head> <meta http-equiv="Expires" content="0"> <meta http-equiv="Cache-Control" content="no-store"> <meta http-equiv="Pragma" content="no-cache"> </head><body><script language="javascript">var aImg=new Image();var photo_width,photo_height;var srcPath="http://images.csdn.net/upimgs/20060124_760_90.jpg"aImg.src=srcPath;function getWidth(){ if (aImg.readyState=="complete"){ if(aImg.width>600){ photo_width=600; photo_height=aImg.height*(600/aImg.width); }else{ photo_width=aImg.width; photo_height=aImg.height; } //alert ("photo_width="+photo_width+"\nphoto_height="+photo_height) document.write("<a href='"+srcPath+"' target='_blank'><img border='0' src='"+srcPath+"' height='"+photo_height+"' width='"+photo_width+"'></a>"); }else setTimeout("getWidth()","100");}getWidth();</script></body></html> 请问readyState属性在非IE的浏览器中被支持吗? 这段jquery代码哪里错误了?怎么无效呢? 编辑aspx 源 视图,引入ckeditor和jquery,无法使用jquery感知 如果让只能web方式下载 EXT grid 数据拖动的问题 怎么用JS实现表单中文本框个数的统计 有关列求和的一点问题 如何才能实现勾选复选框后文本框就不可用了? 请问javascript的变量有没有办法传给asp的变量 关于点击 + 图标即可展现帖子列表或者帖子内容 关于日期转换问题!!! ¥¥¥¥¥¥¥¥给父窗口付值问题¥¥¥¥¥¥¥¥¥¥ div图层显示问题,不知道难不难
==》因为图片还没有加载完毕,所以返回值为0
可以先通过readystate判断图片是否已经加载完成,然后再取width;
<html>
<head>
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-store">
<meta http-equiv="Pragma" content="no-cache">
</head>
<body>
<script language="javascript">
var aImg=new Image();
var photo_width,photo_height;
var srcPath="http://images.csdn.net/upimgs/20060124_760_90.jpg"
aImg.src=srcPath;
function getWidth(){
if (aImg.readyState=="complete"){
if(aImg.width>600){
photo_width=600;
photo_height=aImg.height*(600/aImg.width);
}else{
photo_width=aImg.width;
photo_height=aImg.height;
}
//alert ("photo_width="+photo_width+"\nphoto_height="+photo_height)
document.write("<a href='"+srcPath+"' target='_blank'><img border='0' src='"+srcPath+"' height='"+photo_height+"' width='"+photo_width+"'></a>");
}else setTimeout("getWidth()","100");
}
getWidth();
</script>
</body>
</html>