【发布时间】:2019-03-18 07:43:58
【问题描述】:
我的标记中有一个图像字段。我正在使用 javascript 设置其来源。我需要它的高度和宽度。为此,我使用了 image.height() 和 image.width() 方法。 它在 Internet Explorer 中正常工作,但在 chrome 中不起作用,我尝试了 image.height 和 image.width 方法,但没有得到任何价值。 我也尝试通过将 prop 方法更改为 attr 来设置图像 src,但它也给了我相同的结果。我在这里粘贴我的代码。
function new()
{
timg = new Image();
timg.src=fpath;
}
我用另一种方法调用它
function Size(timg) {
var con=150;
th=timg.height;
alert("th="+th); //in chrome always returns Zero
tw=timg.width;
alert("tw="+tw); //in chrome always returns Zero
}
请指教!
【问题讨论】:
-
将您的 html/css 也显示为工作代码
-
只是表格的宽度和高度
-
尝试使用
Image()构造函数来获取尺寸。 -
是的,我们已经使用 Image() 来获取尺寸,它在 IE 中有效,但在 Chrome 中无效,知道为什么它在 chrome 中无效。
标签: javascript html css asp-classic