javascript - 我如何使用 jQuery 获取 <img> 标签内的宽度

标签 javascript jquery html css

我有以下 img 标签:

   <img id="product-image" src="http://cf.test.com/images/store_logos/thumbnail/43f1ee4d5fe422e9440ab4afe065bbff899b24b0.jpg" width="228" height="304" style="opacity: 1;">

试图提取出 304 高度值:

$('#product-image').height();

但是它总是给我图像的实际大小。 有什么想法吗?

最佳答案

试试这个

$(document).ready(function(){
    alert("Width :"+$('#product-image').width());
});

关于javascript - 我如何使用 jQuery 获取 <img> 标签内的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17161030/

相关文章:

javascript - 如何在 div 滚动到 View 中时自动重复高度和宽度变化?

javascript - Materialise CSS - Select 在 DOM 中没有名称或正确的值

javascript - ASP.NET MVC、IE 11、$(document).ready 和返回导航缓存

html - 如何向多个选定的用户发送邮件

jquery - 根据 Ruby on Rails 中的当前数据库记录更改元素内容

html - CSS:垂直居中水平菜单

javascript - 如何强制 ExtJS 3.4 在隐藏的 tabPanel 上呈现网格

javascript - 如何使用最新的 Browserify (6.x.x) 创建 vendor bundle ?

jquery - Android 横向显示的页面内容不可见

javascript - 如果字符串与 jquery 中的一行匹配,则禁用按钮