如何将箭头的html代码放入模板文字中

发布于 2025-02-03 20:44:50 字数 147 浏览 2 评论 0原文

我想知道如何将HTML箭头放入模板文字中。谢谢。

{sort === "asc" ? `Descending ${\&#8593}`  : `Ascending ${\&#8595}`} 

不起作用。

I am wondering how can I put html arrows in template literals. Thank you.

{sort === "asc" ? `Descending ${\↑}`  : `Ascending ${\↓}`} 

Doesn't work this way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凝望流年 2025-02-10 20:44:50

$ {...}是您将 javascript表达式插入模板字符串的方式。

HTML只是文字。角色参考确实需要以半彩色结束。

{sort === "asc" ? `Descending ↑`  : `Ascending ↓`} 

根本不需要使用模板字符串(由于您没有嵌入JS表达式),因此您应该只使用常规字符串。

${...} is how you insert JavaScript expressions into template strings.

HTML is just text. Character references do need to end in a semi-colon though.

{sort === "asc" ? `Descending ↑`  : `Ascending ↓`} 

There's no need to use template strings at all (since you aren't embedding JS expressions in them), you should just use a regular string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文