javascript - 为什么我的字符串中的尖括号输出不正确?
问题描述
我在字符串中使用尖括号时遇到了困难。我正在尝试输出文件,但显然我不知道如何处理。公平地说,我对这一切都处于一个拖拉的水平,所以我的语言可能是错误的(我是一名作家/视觉设计师;代码不是我的事)。
基本上,如果有东西在尖括号中,我会遇到以下几个问题之一:
如果尖括号中有多个单词,则在尖括号中的单词末尾添加 =“”。
如果它不存在,它会添加结束标签。
如果在文件中,则删除该部分。
我尝试使用 > 和 < 代替 < 和 > 来查看是否可以解决问题,但它只会使用“>”和“<”。
我正在使用这个:
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
尝试转动这样的东西:
"#\n# Configuration stuff below\n# (Based on buttons selected)\n#\n\n Single word items in tags like <this> create another instance of the item as if to close it manually.\n";
"\n\n <extension type>\n Two words in an tag results in added characters.\n </extension>";
"\n\n <input type>\n Use of the word \"input\" in a tag makes the closing tag straight up vanish.\n </input>";
...变成这样的:
#
# Configuration stuff below
# (Based on buttons selected)
#
Single word items in tags like <this> create another instance of the item as if to close it manually.
<extension type>
Two words in an tag results in added characters.
</extension>
<input type>
Use of the word "input" in a tag makes the closing tag straight up vanish.
</input>
但相反,我得到了这个:
#
# Configuration stuff below
# (Based on buttons selected)
#
Single word items in tags like <this> create another instance of the item as if to close it manually.
</this>
<extension type="">
Two words in an tag results in added characters.
</extension>
<input type="">
Use of the word "input" in a tag makes the closing tag straight up vanish.
我正在尝试的精简版本在这里: https ://codepen.io/anon/pen/PoYGmpo
纠正标签中项目问题的最佳方法是什么(没有及时返回并将我的艺术学位变成更实用的东西)?
解决方案
推荐阅读
- r - ggplot 地图图例显示不一致
- node.js - 节点调度器重复
- django - Django-Channels AsyncConsumer 不工作
- optimization - 找到得分最高的非重叠序列的子集
- typescript - 为什么我可以使用临时变量来解决 TypeScript 的对象字面量赋值约束?
- ejb - JCA 远程队列 Wildfly Artemis
- silverstripe - 切换主题后无法访问编辑器
- react-native - React Native:将图像并排对齐在一行上,并具有动态数量的图像
- javascript - 短回调函数语法背后的原理
- javascript - pinterest 可以有多个用户定义的事件吗?