【发布时间】:2011-12-19 04:07:09
【问题描述】:
如何将a 中的所有文本更改为
继续阅读
使用 jquery
<div class="post-read">
<a href="http://www.google.com">Read More</a>
</div>
【问题讨论】:
如何将a 中的所有文本更改为
继续阅读
使用 jquery
<div class="post-read">
<a href="http://www.google.com">Read More</a>
</div>
【问题讨论】:
应该这样做:
$('.post-read a').html('continue reading');
【讨论】:
$('.post-read a').html("continue reading")
【讨论】:
通过 jQuery 中的 text 属性更改 <tag> 的内部文本
$(document).ready(function () {
$('.postread a').text("your new text here ");
}
【讨论】:
innerText() 方法。
在文档就绪处理程序 ($(fn)) 中使用 jQuery...
$('.post-read a').text('continue reading');
为了它,这里是如何在没有 jQuery 的情况下做到这一点......
var anchor = document.getElementsByClassName('post-read')[0].getElementsByTagName('a')[0],
textProperty;
if (anchor.textContent) {
textProperty = 'textContent';
} else if (anchor.innerText) {
textProperty = 'innerText';
}
anchor[textProperty] = 'continue reading';
这对你的 HTML 很有效,但它不是太通用。
如果您不关心设置innerText 属性,您可以使用...
anchor.textContent = anchor.innerText = 'continue reading';
我不推荐它。
【讨论】: