喜 我们有任何jquery方法接受一个int值并返回单词中的值吗?
由于
答案 0 :(得分:2)
不,但你可以自己制作。
这样的事情可能是一个很好的起点,虽然它有一些错误:
http://abhisanoujam.blogspot.com/2009/07/having-fun-with-jquery-numbers-to-words.html
或者这个普通的JavaScript版本:
答案 1 :(得分:1)
这是一个从1到999的代码片段,您可以从http://snippets.dzone.com/posts/show/3710修改为更高的代码:
var units = new Array ("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen");
var tens = new Array ("Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety");
function num(it) {
var theword = "";
var started;
if (it>999) return "Lots";
if (it==0) return units[0];
for (var i = 9; i >= 1; i--){
if (it>=i*100) {
theword += units[i];
started = 1;
theword += " hundred";
if (it!=i*100) theword += " and ";
it -= i*100;
i=0;
}
};
for (var i = 9; i >= 2; i--){
if (it>=i*10) {
theword += (started?tens[i-2].toLowerCase():tens[i-2]);
started = 1;
if (it!=i*10) theword += "-";
it -= i*10;
i=0
}
};
for (var i=1; i < 20; i++) {
if (it==i) {
theword += (started?units[i].toLowerCase():units[i]);
}
};
return theword;
}
答案 2 :(得分:0)
不,没有内置于提供该功能的JavaScript或jQuery中。
答案 3 :(得分:0)
尝试jquery.num2words.js