如何在用户单击 link 并检索 link 内容时执行 JQuery 脚本?
How to perform a JQuery script when the user click on a link and retrieve the link content?
我是 jQuery 的新手,遇到以下问题。
在我的 HTML 中,我有一个 link 这样的:
<a>SAIC831003</a>
单击 link 时,我需要在单击 link 时执行 jQuery 脚本,并在该脚本中检索 <a>
标记的内容。
我想我可以在 <a>
标签上使用 onClick()
(但我不知道这是否是最佳解决方案),但我不知道如何检索内容。
这段代码可以完成工作:
$(function() {
$('a').click(function() {
alert($(this).text()); // Will alert the content of the a tag
});
});
我是 jQuery 的新手,遇到以下问题。
在我的 HTML 中,我有一个 link 这样的:
<a>SAIC831003</a>
单击 link 时,我需要在单击 link 时执行 jQuery 脚本,并在该脚本中检索 <a>
标记的内容。
我想我可以在 <a>
标签上使用 onClick()
(但我不知道这是否是最佳解决方案),但我不知道如何检索内容。
这段代码可以完成工作:
$(function() {
$('a').click(function() {
alert($(this).text()); // Will alert the content of the a tag
});
});