jQuery:如何获取html属性的值? [英] jQuery: How to get the value of an html attribute?

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

问题描述

我有一个html锚元素:

I've got an html anchor element:

<a title="Some stuff here">Link Text</a>

...我想获取标题的内容,以便将其用于其他用途:

...and I want to get the contents of the title so I can use it for something else:

$('a').click(function() {
    var title = $(this).getTheTitleAttribute();
    alert(title);
});

我该怎么做?

推荐答案

$('a').click(function() {
    var title = $(this).attr('title');
    alert(title);
});

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

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