最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use superscript in an html text input tag? - Stack Overflow

programmeradmin4浏览0评论

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:

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

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

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

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:

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

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

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

Share Improve this question asked Dec 3, 2014 at 11:38 kramer65kramer65 53.9k132 gold badges329 silver badges522 bronze badges 2
  • check this out: stackoverflow.com/questions/17683654/… – Aditya Commented Dec 3, 2014 at 11:46
  • Both Rhumborl and Lekhnath have correct answers. – rfornal Commented Dec 3, 2014 at 11:48
Add a comment  | 

5 Answers 5

Reset to default 8

How about using HTML Entities

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

Yes it works

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

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

Also this answer might be of help.

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="m²" 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>

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

<input type="text" placeholder="m²" />

Try this, You can use,

HTML Entity (Named) &sup2;

HTML Entity (Decimal) &#178;

HTML Entity (Hexadecimal) &#x00B2;

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

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

发布评论

评论列表(0)

  1. 暂无评论