我的问题是我的客户将以任何其他语言输入值。假设是马拉地语。我需要根据输入创建账单。 我所做的就是将用户输入的内容作为字符串并为其分配值,这一直有效到0-9,但是10、100、1000等等呢? 这是我的代码,请建议
function convert_number()
{
var no1 = document.getElementById('rate').value
if(no1 == "०")
{
no1 = 0;
alert(no1);
}
else if(no1 == "१")
{
no1 = 1;
alert(no1);
}
else if(no1 == "२")
{
no1 = 2;
alert(no1);
}
else if(no1 == "३")
{
no1 = 3;
alert(no1);
}
else if(no1 == "४")
{
no1 = 4;
alert(no1);
}
else if(no1 == "५")
{
no1 = 5;
alert(no1);
}
else if(no1 == "६")
{
no1 = 6;
alert(no1);
}
else if(no1 == "७")
{
no1 = 7;
alert(no1);
}
else if(no1 == "८")
{
no1 = 8;
alert(no1);
}
else if(no1 == "९")
{
no1 = 9;
alert(no1);
}
else
{
alert('invalid')
}
}
最佳答案
你可以get the UTF-16 code Angular 色的,所以你甚至不需要一个开关
var no1 = document.getElementById('rate').innerHTML
alert(no1.charCodeAt(0));
<p id="rate">r</p>
关于javascript - 在 JavaScript 中将参数作为字符串并转换为数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42923367/