如何使用JQuery获取HTML元素的属性? [英] How to get the attributes of a HTML element using JQuery?

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

问题描述



示例


我想知道是否有一种方法可以在给定的HTML元素中使用JQuery获取值?

 < span id =45463_test>< / span> 

(使用正确的代码处理代码)



我想要的是 id 中的'45463_test'属性(使用JQuery)。

Thanx为响应和编辑。



我会这样让我可以获得已被点击的标签的属性值。

解决方案

如果您只想获取< span /> ,那么最好对每个跨度应用一个点击事件处理程序并捕获该属性值。



< pre $ $(span)。click(function(){
return $(this).attr(id);
});


I am wondering whether there is a way in which I can get the value within a given HTML element using JQuery?

Example

<span id="45463_test"></span>

(using the proper tags made the code to processed)

What I want is the '45463_test' value within the id attribute (using JQuery).

Thanx for the responses and the edit.

I would it such that I can get the attribute value of a tag which has been clicked.

解决方案

If you only want to get the ID of the <span/> you clicked then it's better to apply a click event handler to each span and catch the attribute value.

$("span").click(function() {
  return $(this).attr("id");
});

这篇关于如何使用JQuery获取HTML元素的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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