简体   繁体   English

我如何获得内部的宽度 <img> 使用jQuery标记

[英]how do I get the width inside the <img> tag using jQuery

I have the following img tag: 我有以下img标签:

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

Trying to extract out the 304 height value: 尝试提取304高度值:

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

However it always gives me the actual size of the image. 但是,它总是给我图像的实际尺寸。 Any ideas? 有任何想法吗?

Try this 尝试这个

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

用这个

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

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

Try to get the height after the image rendered: 尝试在渲染图像后获得高度:

$(document).ready(function() {
    $('#product-image').load(function() {
        alert($(this).height());
        alert($(this).width());
    });
});

If your using JQuery before 1.6 means 如果您在1.6之前使用JQuery意味着

$('#product-image').attr("height")

other wise 除此以外

$('#product-image').prop("height")

Will give you answer 会给你答案

将图像放入div并取div的大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM