日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

html5 上标,HTML5 Canvas +下标和上标

發布時間:2024/3/13 HTML 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5 上标,HTML5 Canvas +下标和上标 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

答案和評論是完美的,我想補充一點,你可以通過將字符代碼移動8272輕松地將數字轉換為下標,這對應于“0”(代碼8320)的字符代碼與為“0”(代碼48)。

例如:

var text = "N1234567890";

function subNums(str)

{

var newStr = "";

for (var i=0; i

{

// Get the code of the current character

var code = str.charCodeAt(i);

if (code >= 48 && code <= 57)

{

// If it's between "0" and "9", offset the code ...

newStr += String.fromCharCode(code + 8272);

}

else

{

// ... otherwise keep the character

newStr += str[i];

}

}

return newStr

}

// Get the context

var ctx = document.getElementById('myCanvas').getContext('2d');

// Write the string

ctx.font = "20px serif";

ctx.fillText(text, 0, 20);

ctx.fillText(subNums(text), 0, 40);

這顯然只是一個將所有數字轉換為下標的快速示例,而不一定是您一直想要的數字!

更有用的可能是直接將數值轉換為下標,您可以遍歷所有數字并創建一個字符串,其字符在“0”(代碼8320)和“?”(代碼8329)之間:

// Numerical value to use as subscript

// Don't start it with 0 otherwise it will be read as an octal value!

var index = 1234567890;

function toSub(value)

{

var str = "";

// Get the number of digits, with a minimum at 0 in case the value itself is 0

var mag = Math.max(0, Math.floor(Math.log10(value)));

// Loop through all digits

while (mag >= 0)

{

// Current digit's value

var digit = Math.floor(value/Math.pow(10, mag))%10;

// Append as subscript character

str += String.fromCharCode(8320 + digit);

mag--;

}

return str;

}

// Get the context

var ctx = document.getElementById('myCanvas').getContext('2d');

// Write the string

ctx.font = "20px serif";

ctx.fillText("N" + index, 0, 20);

ctx.fillText("N" + toSub(index), 0, 40);

總結

以上是生活随笔為你收集整理的html5 上标,HTML5 Canvas +下标和上标的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。