如何更改元素中的文本值?

Yus*_*liq 15 jquery replace

如何更改ato中的所有文本

继续阅读

使用jquery

<div class="post-read">
<a href="http://www.google.com">Read More</a>
</div>
Run Code Online (Sandbox Code Playgroud)

ale*_*lex 31

在文档就绪处理程序($(fn))中使用jQuery做它...

$('.post-read a').text('continue reading');
Run Code Online (Sandbox Code Playgroud)

jsFiddle.

为了它,这里是没有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';
Run Code Online (Sandbox Code Playgroud)

jsFiddle.

这对你的HTML片段很有用,但它不太通用.

如果你不关心设置innerText属性,你可以使用...

anchor.textContent = anchor.innerText = 'continue reading';
Run Code Online (Sandbox Code Playgroud)

我不会推荐它.


Cli*_*ive 5

这应该这样做:

$('.post-read a').html('continue reading');
Run Code Online (Sandbox Code Playgroud)