开发者

How to Add text with superscript to a Button

I have a HTML button like

<input t开发者_Python百科ype="button" id="button" onclick="showSuper()" value="Click Me!" />

Inside JavaScript, I have

var showSuper = function() {
    var btn = document.getElementById('button');
    var spanSuper = "<sup>3</sup>";
    btn.value="You Clicked Me " +  spanSuper;
    //btn.value = "You Clicked Me " + <sup>a</sup>;
}

With the above function the button value is getting replaced with You Clicked Me <sup>3</sup>

I also tried with the comment statement that also didn't succeed. How can add a superscripted text to the button?


You do not need script to do this. Use this instead

<button name="button" id="button" onclick="showSuper()">Click Me!</button>

Script

var showSuper = function() {
    var btn = document.getElementById('button');
    var spanSuper = "<sup>3</sup>";
    btn.innerHTML= "You Clicked Me " +  spanSuper;
}

Check Demo. Updated Demo with your solution


If you want to change the value of the button after click. As per Starx suggested add something like this.

HTML

<button onclick="showSuper(this);">Click Me</button>

JS

function showSuper(btn){

    btn.innerHTML="You Clicked Me" + "<sup>3</sup>";

}   


You can use Unicode text like this: <input type="button" value="☺" /> or you can do this<sup>1</sup> AND then copy the one or this ¹ aka`value="¹"

Things You Can do to get them:

SEARCH Alt(unicode) superscript (Letter or number) and you should find somthing like this fn alt(laptop)or alt (numlock on) 1223 and release all at the same time

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜