jQuery获取属性 [英] jQuery get attribute

查看:62
本文介绍了jQuery获取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取具有特定div的所有图像的source属性但不知何故它一直告诉我函数.attr()不存在...

I'm trying to get the source attribute of all images withing a specific div but somehow it keeps telling me that the function .attr() doesn't exist...

这就是功能。 Firebug还告诉我这个是一个图像元素。
我正在使用jQuery v1.3.2

That's the function. Firebug also tells me that "this" is an image element. I'm using jQuery v1.3.2

$('#products LI DIV IMG').each(function() { 
  var image = this;
  alert(image.attr('src'));
});

知道如何解决这个问题吗?

Any idea how to fix that?

提前致谢!

推荐答案

你必须使它成为一个jquerby对象来访问attr('src')。

You have to make it a jquerby object to access attr('src').

var image = $(this);
alert(image.attr('src'));

或者你可以使用

var image = this;
alert(image.src);

这篇关于jQuery获取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆