作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 asp:Repeater
这使得一张 table 有几个 <td>
s 和 <tr>
秒。在每个<tr>
s,我有一个 <a></a>
.
现在,在某个事件中我只想更改 <a></a>
<tr>
中的标签.
所以,我想做这样的事情:
$("a").text("I changed!");
,但我只想更改 <a>.text
在一个<tr>
, 不是所有的 <a>
页面上的元素。
我正在试验 .closest()
,但遗憾的是,您对 jQuery 的了解还不够多,无法实现此功能。
最佳答案
如果您以某种方式获得了目标 tr
,那么您可以使用以下代码找到其中的 a
标记:
tr.find("a").text("text here");
如何找到 tr
实际上取决于您所处的环境以及您的目标 tr
与其他人的区别。
例如如果它是“第一个”tr,你可以说:
var tr = $("tr").first();
如果它是事件发生的元素(例如点击事件):
var tr = $(this);
如果您遇到目标 tr
的子元素,您可以说:
var tr = $(this).closest("tr");
关于javascript - 使用 jQuery 更改特定 <a> 文本的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11354221/
我是一名优秀的程序员,十分优秀!