Word到Word - jquery

时间:2011-08-31 13:27:30

标签: javascript jquery

任何人都知道这是一种描述现金价值或插件的方法吗?

exp:如果我有$ 1.200.000,00且用户hover()值: 描述将是“一百二十

谢谢!

5 个答案:

答案 0 :(得分:13)

以下页面提到了一个非常简单的实现:

Number to Words | Javascript

可以使用此功能执行转换:

var words = toWords(num);

使用jQuery,你可以将它包装在你的悬停函数中,如下所示:

//This will add a tooltip upon hovering with the "word" value.
$('div').hover(function(){
    $(this).attr('title',toWords($(this).text()));
});

<强> Working Demo

答案 1 :(得分:2)

应检查此示例的来源,通过一些修改,您应该能够实现此目的:

http://abhisanoujam.blogspot.com/2009/07/having-fun-with-jquery-numbers-to-words.html

答案 2 :(得分:1)

这是一个既紧凑又运行良好的Javascript解决方案:

Number to Words

可以像这样使用:

var words = toWords(num);

答案 3 :(得分:0)

验证只允许一个点的文本框

if(!document.getElementById("per").value.match(/^[0-9]*\.?[0-9]*$/)) //"per" is the id text box
{
   alert("Enter Correct Interest Rate");
   return (false);
}

我希望这可能有所帮助。

答案 4 :(得分:0)

you can add this code for number to word.if your field are coming dynamic.Just apply the class ".numtowordcls" on your input type

function getNumberToWord(thisObj){
        var dataType=$(thisObj).attr("dir");

         if(dataType!=null && dataType!="" ){
            var value=$(thisObj).val();
            if(dataType==='decimal' || dataType==='currency' || dataType==='number' || dataType==='emd' ){
                if(value!=undefined && value.trim()!="" ){
                    if(isNaN(value)){
                    alert("Kindly Enter Valid Value For Filed Type '"+dataType+"'");
                    $(thisObj).val("");
                    $(thisObj).focus();
                    }else{
                        if(value!=undefined && value.trim()!=""){
                            if(!$.isNumeric(value)){
                            alert("Please Eneter Numeric value !!!");
                            $(this).val('');
                            return false;
                            }

                            var firstPart=value.toString().split(".")[0];
                            if(firstPart.length>14){
                                alert("Please Enter value upto 14 Digit !!!");
                                $(thisObj).val(value.substr(0,14));
                                $(thisObj).focus();
                                return false;
                            }
                            var secondPart=value.toString().split(".")[1];
                            if(secondPart!=undefined && secondPart!="" && secondPart.length>2){
                                alert("Decimal allowed upto 2 places !!!");
                                $(thisObj).val(value.substr(0,14));
                                $(thisObj).focus();
                                return false;
                            }  
                        }
                    }
                }

            }

        } 
        $(".numtowordcls").each(function(){
            var id=$(this).attr("id");
            var dirObj=$(this).attr("dir");
            var dataArray=id.split("_");
            var finalId=dataArray[0]+"_"+dataArray[1]+"_"+dirObj;
            var fieldvalue=$("#"+finalId).val();
            if(fieldvalue!=undefined && fieldvalue.trim()!=""){
                var ntwidvalue=ntwidvalue+""+$(this).attr("id")+"~~~"+parseFloat(fieldvalue)+"~~~~";

            }else{
                $('#'+id).val("");
            }

        });
        console.log("aaaa");
        $('button').click(function(){
            var input = $('input');
            input.val('ntwidvalue');
            input.trigger('input');
        });
    }