使用 jQuery,我可以在单击时更改图像的 src
$("#thumb li img").click(function() {
var newlinkimage = $(this).attr("src");
newlinkimage = newlinkimage.substring(14,17);
$("#avant img").attr("src", 'retouche-hr' + newlinkimage + '-a.jpg');
$("#apres img").attr("src", 'retouche-hr' +newlinkimage + '-b.jpg');
问题是,新图像宽度与旧图像宽度不同。我如何获得新图像的原始宽度(就像在 Dreamweaver 中获得的小箭头
最佳答案
这是简单的 JavaScript 方法。将其集成到您的代码中应该很容易。
var newimage = new Image();
newimage.src = 'retouche-hr' + newlinkimage + '-a.jpg'; // path to image
var width = newimage.width;
var height = newimage.height;
关于jquery - jquery 中的图像 native 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1643858/