jquery中获取图片真实大小的方法:1、方法一【.attr("src", $(''#imgid").attr("src"))】;2、方法二【theImage.src = $(''#imgid").attr( "src");】。
本教程操作环境:windows10系统、
jquery
2.2.4,本文适用于所有品牌的电脑。
jquery中获取图片真实大小的方法:
第一种:
第二种:
基于jQuery的AJAX和JSON的实例 中文WORD版
本文档主要讲述的是基于jQuery的AJAX和JSON的实例;过jQuery内置的AJAX功能,直接访问后台获得JSON格式的数据,然后通过jQuer把数据绑定到事先设计好的html模板上,直接在页面上显示。有需要的朋友可以下载看看
下载
第一种要安全性要高些,保证是在图片加载完成后在获取。
相关免费学习推荐:
JavaScript
(视频)
$("") // Make in memory copy of image to avoid css issues 在内存中创建一个img标记
.attr("src", $(''#imgid").attr("src"))
.load(function() {
pic_real_width = this.width; // Note: $(this).width() will not
pic_real_height = this.height; // work for in memory images.
});var theImage = new Image();
theImage.src = $(''#imgid").attr( "src");
alert( "Width: " + theImage.width);
alert( "Height: " + theImage.height);