twitter-bootstrap 如何在 html 文本输入标签中使用上标?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27270820/
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-21 21:57:21  来源:igfitidea点击:

How to use superscript in an html text input tag?

javascripthtmlcsstwitter-bootstrap

提问by kramer65

I've got a simple input tag (which I prettify using Bootstrap) in which I now want to place a superscript (to display "m2"). The problem is that when I do this:

我有一个简单的输入标签(我使用 Bootstrap 对其进行美化),我现在想在其中放置一个上标(以显示“m 2”)。问题是,当我这样做时:

<input class="form-control" name="gla" placeholder="m<sup>2</sup>" type="text">

the placeholder literally shows this: m<sup>2</sup>

占位符字面上显示了这一点: m<sup>2</sup>

Does anybody know how I can properly display the superscript? All tips are welcome!

有人知道如何正确显示上标吗?欢迎所有提示!

采纳答案by lmazgon

You could just use the UTF-8 character for superscripted 2. Also be sure to set the charset of the document to UTF-8.

您可以只使用 UTF-8 字符作为上标 2。另外请确保将文档的字符集设置为UTF-8.

<html>
    <head>
        <meta charset="UTF-8"> 
    </head>
    <body>
        <input class="form-control" name="gla" placeholder="m2" type="text" />
    </body>
</html>

Also this answermight be of help.

同时这个答案可能会有所帮助。

回答by Lekhnath

How about using HTML Entities

如何使用 HTML 实体

<input class="form-control" name="gla" placeholder="m&sup2;" type="text">

Yes it works

是的,它有效

回答by Rhumborl

You should be able to insert the 2 character directly into the html tag - it is ascii code 262/ octal 178. This should render safely as it is just ASCII, not Unicode.

您应该能够将 2 个字符直接插入到 html 标记中 - 它是 ascii 代码 262/八进制 178。这应该可以安全地呈现,因为它只是 ASCII,而不是 Unicode。

<input type="text" placeholder="m2" />

回答by Jukka K. Korpela

Within an attribute value, you can use characters just like in document content (except for the quote character used as attribute value delimiter). This means that you can write the superscript two character as such, or using a named character reference, or a numeric reference. When using the character as such, you need to make sure that the character encoding is properly declared (corresponds to the actual encoding).

在属性值中,您可以像在文档内容中一样使用字符(用作属性值分隔符的引号字符除外)。这意味着您可以这样写上标两个字符,或者使用命名字符引用或数字引用。当这样使用字符时,您需要确保正确声明字符编码(对应于实际编码)。

<input class="form-control" name="gla" placeholder="m2" type="text"><br>
<input class="form-control" name="gla" placeholder="m&sup2;" type="text"><br>
<input class="form-control" name="gla" placeholder="m&#178;" type="text"><br>
<input class="form-control" name="gla" placeholder="m&#xb2;" type="text"><br>

回答by Krish R

Try this, You can use,

试试这个,你可以使用,

HTML Entity (Named) &sup2;

HTML 实体(命名) &sup2;

HTML Entity (Decimal) &#178;

HTML 实体(十进制) &#178;

HTML Entity (Hexadecimal) &#x00B2;

HTML 实体(十六进制) &#x00B2;

 <input class="form-control" name="gla"  placeholder="m&#178;" type="text">

Demo : http://jsfiddle.net/q8310f27/1/

演示:http: //jsfiddle.net/q8310f27/1/