首页 > 解决方案 > 如何使用 javascript 处理自定义 html 标签

问题描述

例如,我得到的 HTML 包含词汇表条目的自定义标签:我想我可以自动将其替换为 aa href但是,它没有按预期工作。

根据到目前为止的答案,我已经修改了一些东西,现在我有了这个

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
  $( "glo" ).each(function(index){  
	var x = ( $( this ).attr("name") );
		link = document.createElement("a"); 
		link.setAttribute('href', '../../QA-C/Messages/Glossary.html#' + x);
		var y = ($( this).text());
				$(this).html('');
				link.innerHTML = y;
				$("glo")[index].prepend(link);
        });
    });
});
 
</script>
</head>
<body>

<h2>This is a heading</h2>

   <p>
            <p>
            <glo name ="size_t">size_t</glo> is defined by a typedef in the standard library header files <code class="nm">&lt;stdio.h&gt;, &lt;stddef.h&gt;, &lt;stdlib.h&gt;, &lt;string.h&gt;</code> and <code class="nm">&lt;time.h&gt;</code>.
</p>
        <p>
QA C has an option (-intrinsictype), which allows the type associated with <i>size_t</i> to be configured.
Message 0040 is generated if a <i>typedef</i> encountered in the source code is not consistent with this configured type.
</p>
        <p>
The <glo name="QA_C.Standard.Library.header.files">QA_C.Standard.Library.header.files</glo> use an implicit macro, <i>PRQA_SIZE_T</i>, when declaring the type of <i>size_t</i>.
This macro is automatically defined in the QA C environment to reflect the configuration option setting.
If you are using your own header files to define <i>size_t</i>, you should ensure that QA C is configured to be consistent with this typedef.
</p>

</p>
<p>
<glo name="size_t">size for size_t</glo> some text to test
</p>

<button>Click me</button>

</body>
</html>

所以这行得通,但我相信必须有一种更优雅的方式来做到这一点。

标签: javascripthtmlcustom-tags

解决方案


推荐阅读