Cómo seleccionar el ancho de la imagen src - Jquery
Frecuentes
Visto 330 veces
0
How do I select the width of selected image on choose file?
if(new Image().attr('src').width() < 200){
alert('Expected');
}else{
alert('Woah?');
}
1 Respuestas
0
To select the source and width of an image using Javascript (not jQuery specific):
Aquí hay un 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
Respondido el 10 de Septiembre de 13 a las 00:09
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript jquery if-statement alert or haz tu propia pregunta.
What do you mean by "selected image"? You've provided some invalid code. What have you actually attempted so far? - user2736012
Yes, the code doesn't seem to be working. '<input type="file">' selected files width is what I want to detect. - Shogg
<input type="file">
* - ShoggYou're going to need to do a better job of explaining what you want. Take it a step at a time, and spell it out in your question. The code you provided is an odd mix of function calls that will simply fail. - user2736012
You can't check the width until the image is uploaded. - Itay