如何在jquery中检查图像文件大小?

编程入门 行业动态 更新时间:2024-10-27 16:26:37
本文介绍了如何在jquery中检查图像文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

点击该按钮时我有一个按钮我需要获取图像文件大小

I have a button while clicking that button I need to get the image file size

function attachPhoto() { var path="www.w3schools/images/pulpit.jpg";// i need to check size of image } <input type="button" style="width:30%" onClick=" attachPhoto()" />

推荐答案

这是一个非jQuery解决方案:

Here's a non-jQuery solution:

function attachPhoto() { var img = new Image(); img.onload = function() { alert([img.width, img.height]); } img.src = "www.w3schools/images/pulpit.jpg"; }

请注意,图片大小仅可用加载文件后, onload 回调将被异步调用 。如果你想知道必须从里面那个回调中触发的大小,你想要发生其他事情。

Note that the image size will only be available once the file is loaded, and the onload callback will be called asynchronously. If you want other stuff to happen once you know the size that must be triggered from inside that callback.

更多推荐

如何在jquery中检查图像文件大小?

本文发布于:2023-06-09 06:30:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/596872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件大小   图像   如何在   jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!