问题描述:

How do I select the width of selected image on choose file?

if(new Image().attr('src').width() < 200){

alert('Expected');

}else{

alert('Woah?');

}

网友答案:

To select the source and width of an image using Javascript (not jQuery specific):

Here's a jsFiddle, and here's the js code:

var test_image = document.getElementById("TestImage");
var test_image_src = test_image.getAttribute("src"); // get the source
var test_image_width = test_image.getAttribute("width"); // get the width

if(test_image_width < 200){
    alert('Expected');
}else{
    alert('[Woah]?');
}

You can retrieve any attribute using this method.

var attribute = element.getAttribute(attributeName);
https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute

相关阅读:
Top