使用JQuery查找A标签的值/文本 [英] Finding the value/text of an A tag using JQuery
本文介绍了使用JQuery查找A标签的值/文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里不太正确.
$(document).ready(function()
{
$("a#edit").click(function() {
$("div#search").addClass("hidden");
$("div#edit").removeClass("hidden");
alert((this).val());
return false;
});
}
);
后来:
<a href="#" id="edit">10.1001</a>
我想从中获取值"10.1001". alert((this).val());
似乎无效,alert((this).text());
也无效.有人可以很快地指出我在这里缺少什么吗?谢谢!
I want to get the value "10.1001" from this. alert((this).val());
doesn't seem to work, nor does alert((this).text());
. Can someone point out really quickly what I'm missing here? Thanks!
推荐答案
您需要$(this).text()
代替锚,而不是(this).val()
.
Instead of (this).val()
you want $(this).text()
for anchors.
.val()
用于输入类型元素,
.val()
is for input type elements, .text()
is used to get the text within a tag :)
您的代码总体上应该看起来像这样,请注意在(this)
之前添加的$
:
Your code should look like this overall, note the addd $
before (this)
:
$(function() {
$("a#edit").click(function() {
$("div#search").addClass("hidden");
$("div#edit").removeClass("hidden");
alert($(this).val());
return false;
});
});
这篇关于使用JQuery查找A标签的值/文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文