如何更改元素中的文本值?
如何更改a
中的所有文本
继续阅读
使用jquery
在文档就绪处理程序( $(fn)
)中使用jQuery做…
$('.post-read a').text('continue reading');
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';
jsFiddle 。
这对你的HTML片段很有用,但它不太通用。
如果你不关心设置innerText
属性,你可以使用…
anchor.textContent = anchor.innerText = 'continue reading';
我不会推荐它。
这应该这样做:
$('.post-read a').html('continue reading');
$('.post-read a').html("continue reading")
通过jQuery中的text属性更改
的内部文本
$(document).ready(function () { $('.postread a').text("your new text here "); }