Home > Web Front-end > JS Tutorial > Example discussion on the impact of img loading on height() under chrome_javascript skills

Example discussion on the impact of img loading on height() under chrome_javascript skills

WBOY
Release: 2016-05-16 16:46:57
Original
1212 people have browsed it
复制代码 代码如下:





chrome下img加载对height()的影响











这是文字


这里显示结果。





将此代码在chrome运行,当alert窗口弹出时,将会发现页面的img并没有加载。

运行结果如下:

这是文字
showImg:112&0
showText:18

1、此处 img的默认宽度为112,但是我链接的img的宽度为1000,

2、此处img的高度为0,

现做如下改动
复制代码 代码如下:



运行结果为:

这是文字
showImg:1000&0
showText:18
img的高度仍旧为0

当为其设置高度之后,就可以正常获取到。

结论:在chrome下,img不设置宽高,通过jquery的width()和height()获取到的img的宽高将为112px * 0

求助:希望哪位大侠有好办法,能在不设置宽高情况下获取到正确的值。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template