2017-06-13 38 views
-6

如何使用Javascript替换HTML文本?更改文本的JavaScript

在片段下面,我需要替换文本“作者说”与“作者简介”。

谢谢!

<div id="author-info"> 
    <div class="author-image"> 
     <a class="author-avatar" href="https://www.test.com"><img alt=""></a> 
    </div> 
    <div class="author_name_wrap"> 
     <h4 class="author_name"><a href="https://www.test.com/author/">Author say</a></h4> 
     <div class="author_socicons"></div>  </div> 
</div> 
+0

? – Chris

+0

你想怎么更换呢?你能有点特别吗? – dloeda

+0

我想要在整个网站上发生这种情况 – Ira

回答

-1
$("h4.author_name a").text('About the Author'); 

你可以找到详细的文章here

+0

请注意,jQuery的既不是标记,也没有在问题中提到。我个人认为,如果OP没有提及或标记它们,应该避免框架答案。无论如何,我认为发布一行jQuery代码,而没有提到你使用框架/外部资源是非常没用的,特别是当OP不熟悉JS做文本替换时。 – Santi

+0

谢谢!看起来这个链接不起作用。 – Ira

0

要更改HTML标记使用的innerHTML属性的内容:你想要什么样的事件这种变化发生

var h4 = document.getElementsByClassName("author_name")[0], 
    target = h4.childNodes[0]; 
target.innerHTML = "About the author";