jQuery .attr检索自定义属性返回未定义 [英] jQuery .attr retrieving custom attribute returns undefined

查看:213
本文介绍了jQuery .attr检索自定义属性返回未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用jquery时遇到以下问题.

i have the following problem using jquery.

我有这样的事

<div id="yxz" value="1">
  <span class="delete"></span>
</div>

现在我有了这个fn,但是它只返回未定义",但是它确实返回ID或类(如果我要求这样做).

now I have this fn but it only returns "undefined", it does however return the id, or class if I ask for this.

$(".delete").click(function(){
  alert($(this).parent("div").attr("value"));
});

我曾经用相同的attr东西来获得这个值.现在是否使用jquery 1.6.1代替1.5.2.与我有关系?

I used to get this value with the same attr stuff. Does this have sth to do with me using the jquery 1.6.1 now instead of 1.5.2.

感谢您的帮助.

推荐答案

要检索元素的值,请使用 val( ).由于div没有值,因此您应该使用 data()来设置和获取数据.

To retrieve the value of elements, use val(). Since divs don't have values, you should use data() to set and get data.

这篇关于jQuery .attr检索自定义属性返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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