简体   繁体   English

从javascript函数设置HTML段落中的文本而不进行格式化

[英]Set text in HTML paragraph from javascript function without formatting

How can I add text to a HTML paragraph without adding formatting to the inserted text? 如何在不向插入的文本添加格式的情况下向HTML段落添加文本? This is what I have so far: 这是我到目前为止:

 <p>Example paragraph <ins id="example"></ins>.</p> <script> function getIt() { return "it" } document.getElementById("example").innerHTML = getIt(); </script> 

When the word "it" is inserted, it is underlined. 当插入单词“it”时,它带有下划线。 How dow I prevent it from being underlined? 我如何防止它被加下划线?

Thank you! 谢谢!

This is because by default there there is text decoration underline in ins tag of html,you can override it by including the below css code in your head sect 这是因为默认情况下,html的ins标签中有文本修饰下划线,您可以通过在头部包含以下css代码来覆盖它

<style>
ins { 
    text-decoration: none;
}
</style>

 ins{ text-decoration: none; } 
 <p>Example paragraph <ins id="example"></ins>.</p> <script> document.getElementById("example").style.textDecoration = "none"; function getIt() { return "it" } document.getElementById("example").innerHTML = getIt(); </script> 

You should set text-decoration: none; 你应该设置text-decoration: none;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM