• 金额大小写转换和input失去焦点触发事件


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script>
    function regInput(reg)
    {
    var srcElem = event.srcElement
    var oSel = document.selection.createRange()
    oSel = oSel.duplicate()
    oSel.text = ""
    var srcRange = srcElem.createTextRange()
    oSel.setEndPoint("StartToStart", srcRange)
    var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length)
    event.returnvalue = reg.test(num)
    }

    function chineseNumber(num)
    {
    if (isNaN(num) || num > Math.pow(10, 12)) return ""
    var cn = "零壹贰叁肆伍陆柒捌玖"
    var unit = new Array("拾佰仟", "分角")
    var unit1= new Array("万亿", "")
    var numArray = num.toString().split(".")
    var start = new Array(numArray[0].length-1, 2)

    function toChinese(num, index)
    {
    var num = num.replace(/d/g, function ($1)
    {
    return cn.charAt($1)+unit[index].charAt(start--%4 ? start%4 : -1)
    })
    return num
    }

    for (var i=0; i<numArray.length; i++)
    {
    var tmp = ""
    for (var j=0; j*4<numArray[i].length; j++)
    {
    var strIndex = numArray[i].length-(j+1)*4
    var str = numArray[i].substring(strIndex, strIndex+4)
    var start = i ? 2 : str.length-1
    var tmp1 = toChinese(str, i)
    tmp1 = tmp1.replace(/(零.)+/g, "零").replace(/零+$/, "")
    tmp1 = tmp1.replace(/^壹拾/, "拾")
    tmp = (tmp1+unit1[i].charAt(j-1)) + tmp
    }
    numArray[i] = tmp
    }

    numArray[1] = numArray[1] ? numArray[1] : ""
    numArray[0] = numArray[0] ? numArray[0]+"圆" : numArray[0], numArray[1] = numArray[1].replace(/^零+/, "")
    numArray[1] = numArray[1].match(/分/) ? numArray[1] : numArray[1]+"整"
    return numArray[0]+numArray[1]
    }

    function aNumber(num)
    {
    var numArray = new Array()
    var unit = "亿万圆$"
    for (var i=0; i<unit.length; i++)
    {
    var re = eval("/"+ (numArray[i-1] ? unit.charAt(i-1) : "") +"(.*)"+unit.charAt(i)+"/")
    if (num.match(re))
    {
    numArray[i] = num.match(re)[1].replace(/^拾/, "壹拾")
    numArray[i] = numArray[i].replace(/[零壹贰叁肆伍陆柒捌玖]/g, function ($1)
    {
    return "零壹贰叁肆伍陆柒捌玖".indexOf($1)
    })
    numArray[i] = numArray[i].replace(/[分角拾佰仟]/g, function ($1)
    {
    return "*"+Math.pow(10, "分角 拾佰仟 ".indexOf($1)-2)+"+"
    }).replace(/^*|+$/g, "").replace(/整/, "0")
    numArray[i] = "(" + numArray[i] + ")*"+Math.ceil(Math.pow(10, (2-i)*4))
    }
    else numArray[i] = 0
    }
    return eval(numArray.join("+"))
    }
    </script>
    </head>

    <body>
    <input id=up size=60 onkeypress="regInput(/^d{0,12}(.d{0,2})?$/)" onblur="lw.value = chineseNumber(up.value)"><button onclick="lw.value = chineseNumber(up.value)">
    转为大写</button>//onblur="lw.value = chineseNumber(up.value)"说明鼠标移开焦点出发事件
    <br>
    <input id=lw size=60 value="壹仟壹佰壹拾壹圆整"><button onclick="up.value = aNumber(lw.value)">转为小写</button>
    </body>
    </html>

  • 相关阅读:
    20161020001 DataGridView 选中的 DataGridViewCheckBoxCell 不添加重复项
    20161014006 DataGridView Combobox 数据绑定与传值
    Unity学习链接
    射线碰撞【拖拽物体img,点击后在固定位置显示A(工具),点击A显示B(Toggle组成的表),关闭B显示C(工具)】
    UGUI Text文字左右循环运动
    3d物体平缓摆动
    【转】unity www读取本地视频文件和外部视频文件 播放视频动画和视频声音
    改变图片或文字颜色( Gradient)
    改变图片透明度
    Animation脚本
  • 原文地址:https://www.cnblogs.com/914556495wxkj/p/3852610.html
Copyright © 2020-2023  润新知