javascript 如何将复选标记作为字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11703384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 14:03:34  来源:igfitidea点击:

How to place a checkMark as a character?

javascripthtml

提问by Alegro

$("#status").html('<img src="available.png">Available');  

Instead of checkMark picture I want a chekMark character.
Is there a way, please?

我想要一个 chekMark 字符,而不是 checkMark 图片。
请问有办法吗?

回答by Frédéric Hamidi

You could use U+2713(Check Mark Symbol ?):

您可以使用U+2713(复选标记符号?):

$("#status").text("\u2713 Available"); 

回答by waldyr.ar

Try

尝试

$("#status").html('&#10003;');

回答by hvgotcodes

try either of

尝试其中任何一个

&#10003;

&#x2713;

&#x2713;

one is hex, one is decimal. If I don't put code markers around them, you get

一个是十六进制,一个是十进制。如果我不在它们周围放置代码标记,你会得到

✓ ✓

✓ ✓

回答by cegfault

See this: http://www.danshort.com/HTMLentities/index.php?w=dingb

看到这个:http: //www.danshort.com/HTMLentities/index.php?w=dingb

&#10003;or &#10004;

&#10003;或者 &#10004;

Although I must say that I think a picture is a better option: you can modify it later at any time without changing your code.

虽然我必须说我认为图片是一个更好的选择:您可以在以后随时修改它而无需更改您的代码。

回答by RAN

Try this:

试试这个:

Decimal:

十进制:

&#10003;

or hex:

十六进制:

&#x2713;

example:$("#status").html('&#10003;');

例子:$("#status").html('&#10003;');

回答by cegfault

You can also use a check mark in a web font.

您还可以在 Web 字体中使用复选标记。

This question (and the answers) are now five years old. For the sake of those coming from Google, I wanted to add another option that's become available in recent years, but is not mentioned in previous answers.

这个问题(和答案)现在已经五年了。为了那些来自谷歌的人,我想添加另一个近年来可用的选项,但在之前的答案中没有提到。

You can certainly still use unicode characters (.html("&#10003;")or .text("\u2713"), but in the past few years web fonts have become more common. For example, material icons has a check mark: https://material.io/icons/#ic_check

您当然仍然可以使用 unicode 字符 (.html("&#10003;").text("\u2713"),但在过去几年中,网络字体变得越来越普遍。例如,材质图标有一个复选标记:https: //material.io/icons/#ic_check

Google (who made and maintains material icons) also did a good job of explaining web fonts and how to use them here: https://google.github.io/material-design-icons/

谷歌(谁制作和维护材料图标)也很好地解释了网络字体以及如何在此处使用它们:https: //google.github.io/material-design-icons/

Basically web fonts are the best of both worlds: the customization of images and the usage/dynamics of font characters. The advantages to using web fonts over unicode characters are:

基本上,网络字体是两全其美的:图像的定制和字体字符的使用/动态。使用 web 字体而不是 unicode 字符的优点是:

  • control over style (you can make your own web font character of any style, whereas unicode characters are what they are)
  • use of multiple styles (you can make web fonts with numerous styles of check marks for different situations; you're not locked into one style)
  • code readability (very few developers will know what \u2713or &#10003means, but <i class="myfont">check</i>is easy to understand
  • portability: although every major browser uses a unicode font by default, there are still some computers or devices which may render with a non-unicode font by default. In fact, wikipedia's current list of unicode fontsis decently long, but the supported characters vary widely between each font, and there are clear differences between how the each font is rendered by different platforms. Including a webfont ensures that every user will see the same thing, regardless of platform or default fonts.
  • More options: having an installed webfont allows you to update the style, add new icons/characters to the font, etc. There is no way to currently do this with unicode.
  • 控制样式(您可以制作自己的任何样式的网络字体字符,而 Unicode 字符就是它们的样子)
  • 使用多种样式(您可以针对不同情况制作具有多种样式的复选标记的网络字体;您不会被锁定在一种样式中)
  • 代码可读性(很少有开发人员知道什么\u2713&#10003意味着什么,但<i class="myfont">check</i>很容易理解
  • 可移植性:虽然每个主流浏览器默认使用unicode字体,但仍有一些计算机或设备可能默认使用非unicode字体。事实上,维基百科当前的 unicode 字体列表相当长,但是每种字体之间支持的字符差异很大,并且每种字体在不同平台上的呈现方式也存在明显差异。包含 webfont 可确保每个用户都会看到相同的内容,无论平台或默认字体如何。
  • 更多选项:安装 webfont 允许您更新样式、向字体添加新图标/字符等。目前无法使用 unicode 执行此操作。