javascript - 如何使用 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"><stdio.h>, <stddef.h>, <stdlib.h>, <string.h></code> and <code class="nm"><time.h></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>
所以这行得通,但我相信必须有一种更优雅的方式来做到这一点。
解决方案
推荐阅读
- c# - Ftp 在本地工作,但不适用于已发布的应用程序
- java - 我无法从一项活动切换到另一项活动,而且我在清单上有问题
- javascript - FullCalendar 事件的奇怪行为
- c# - 如何创建将字母分配给特定单词的密码?
- amazon-web-services - AWS EB & Python,如何重置 Elastic Beanstalk 访问密钥和秘密访问密钥?
- python - Queryset 中的 Django "OR" like 语句?
- google-chrome - 使用 chrome 扩展读取和写入文件夹中的文件
- android - Android:底部导航顶部的浮动操作栏不起作用
- flutter - 安装 build_runner 时 Dart SDK 版本不匹配
- python - 将轮子上传到 github 版本时出现资产路径错误