zl程序教程

您现在的位置是:首页 >  前端

当前栏目

javascript全角转换实现代码

JavaScript转换代码 实现 全角
2023-06-13 09:14:11 时间
下面我们来看下这个例子吧!
复制代码代码如下:

<html>
    <head>
        <title>jqueryDemo:quanjiaoNum</title>
        <scriptsrc="jquery.js"src="jquery.js"type="text/javascript"></script>
        <scripttype="text/javascript"><!--
            functionchangeNum(){
                varqjNum=$("input[@name=qjNum]").val();
                vartoAscii=qjNum.charCodeAt();
                if(toAscii>65295&&toAscii<65306&&qjNum.length==11)
                {
                    vartoBack=0;
                    vartemp=0;
                    varunite="";
                    for(vari=0;i<qjNum.length;i++)
                    {
                        toAscii=qjNum.charCodeAt(i);
                        toBack=toAscii-65248;
                        temp=String.fromCharCode(toBack);
                        unite=unite+temp;
                    }
                    alert(unite);
                    returntrue;
                }
                if(toAscii>47&&toAscii<58&&qjNum.length==11)
                {
                    alert(qjNum);
                    returntrue;
                }
                else{
                    alert("请输入正确的手机号码");
                    document.myform.qjNum.value="";
                    returnfalse;
                }
            }

//--></script>
    </head>
    <formname="myform"action="">
        中文数字转换成阿拉伯数字:<inputtype="text"id="qjNum"name="qjNum"/><inputtype="button"value="提交"onclick="changeNum()"/>
    </form>
</html>

这是个判断手机号的问题!另外请注意我这还用到了jquery!记得引入哦……