使用JQuery获取单击标签的文本

时间:2010-01-20 12:52:38

标签: jquery

我正在使用JQuery.live()功能来捕获<div>中任何标签的点击事件。但是点击后,我想获得点击标签的文字。我尝试了$(this).text,但它显示了整个代码。

3 个答案:

答案 0 :(得分:3)

添加括号以使用该方法。

这将获得文本。

$(this).text()

这将设置它。

$(this).text("New Text")

text() in the jQuery docs

答案 1 :(得分:1)

$(this).val()应获取输入值。

答案 2 :(得分:1)

$(this).text返回名为text的函数的代码。

您必须使用以下方法来调用该方法:

  • var myText = $(this).text();获取文字或:
  • $(this).text('some text');设置