简体   繁体   English

如何对 HTML标签进行条带化并将其替换为<h> ?</h>

[英]How can I stripe the HTML <b> tag and replace it with <h>?

I am using a program called anki, a SRS for learning languages.我正在使用一个名为 anki 的程序,这是一个用于学习语言的 SRS。 In anki I have a deck where 1000 cards have a code like this <b>TEXT</b> .在 anki 中,我有一副牌,其中 1000 张卡片有这样的代码<b>TEXT</b> Now I want to replace the <b> and </b> with <h> and </h> to make it look like this <h>TEXT</h> , but I don't know how to do it.现在我想用<h></h>替换<b></b>以使其看起来像这样<h>TEXT</h> ,但我不知道该怎么做。 I tried something like this, which didn't work.我尝试了类似的方法,但没有奏效。 I would appreciate any help.我将不胜感激任何帮助。

<div id="sentence">
{{front}}
</div>

<script>
s = document.querySelector('#sentence');
s.innerHTML = s.innerHTML.replace(/.*<b>(.*)<\/b>.*/, '<p>');
</script>

You could just replace them individually:您可以单独替换它们:

s = document.querySelector('#sentence');
s.innerHTML = s.innerHTML.replace(/<b>/g, '<h>');
s.innerHTML = s.innerHTML.replace(/<\/b>/g, '</h>');

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

相关问题 如何用 h1 替换 HTML 字符串的第一个元素? - How can I replace the first element of an HTML string with an h1? Javascript:如何替换字符串的内容,而不替换HTML标记中的内容? - Javascript: How can I replace the contents of a string but not in an HTML tag? 如何使用“.replace()”和“.html()”将纯文本转换为图像标记? - How can I use “.replace()” and “.html()” to turn plaintext into an image tag? 如何在JavaScript中将HTML标签替换为另一个 - How can i replace HTML tag to another in javascript 如何替换HTML标记中的文本,而不替换href链接中的文本? - How can I replace the text in an HTML tag but not in an href link? 如何用html标签替换字符? (丰富的文字) - How can I replace characters with html tag? (enriching text) 如何替换/更新字符串中的特定 HTML 标记 - How can I replace/update specific HTML tag inside string 如何编写一个脚本来帮助我在 html 的 Div 标签之间添加 H1 标签? - How can I write a script which help me to add H1 tag in between Div tag in html? 如何更改HTML标签颜色(例如h1,h2,p等),但保持某些h1,h2标签不变? - How can I change HTML tag color like h1, h2, p etc but keeping some h1, h2 tag unchanged? 如何用视频标签替换标签 - How can i replace a tag with video tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM