javascript 全角轉(zhuǎn)換實(shí)現(xiàn)代碼
更新時(shí)間:2009年07月17日 00:58:24 作者:
當(dāng)客戶端用戶切換輸入法至全角時(shí)可能您的表單提交會(huì)有漏洞哦!不過事實(shí)上js有這功能 可以將其轉(zhuǎn)換為非全角字符!
下面我們來看下這個(gè)例子吧!
<html>
<head>
<title>jqueryDemo:quanjiaoNum</title>
<script src="jquery.js" src="jquery.js" type="text/javascript"></script>
<script type="text/javascript"><!--
function changeNum(){
var qjNum=$("input[@name=qjNum]").val();
var toAscii=qjNum.charCodeAt();
if(toAscii > 65295 && toAscii < 65306 && qjNum.length == 11)
{
var toBack = 0;
var temp = 0;
var unite = "";
for(var i=0;i < qjNum.length;i++)
{
toAscii=qjNum.charCodeAt(i);
toBack =toAscii-65248;
temp = String.fromCharCode(toBack);
unite = unite + temp ;
}
alert(unite);
return true;
}
if(toAscii > 47 && toAscii < 58 && qjNum.length == 11)
{
alert(qjNum);
return true;
}
else{
alert("請輸入正確的手機(jī)號碼");
document.myform.qjNum.value="";
return false;
}
}
// --></script>
</head>
<form name="myform" action="">
中文數(shù)字轉(zhuǎn)換成阿拉伯?dāng)?shù)字:<input type="text" id="qjNum" name="qjNum"/><input type="button" value="提 交" onclick="changeNum()"/>
</form>
</html>
這是個(gè)判斷手機(jī)號的問題!另外請注意我這還用到了jquery!記得引入哦……
復(fù)制代碼 代碼如下:
<html>
<head>
<title>jqueryDemo:quanjiaoNum</title>
<script src="jquery.js" src="jquery.js" type="text/javascript"></script>
<script type="text/javascript"><!--
function changeNum(){
var qjNum=$("input[@name=qjNum]").val();
var toAscii=qjNum.charCodeAt();
if(toAscii > 65295 && toAscii < 65306 && qjNum.length == 11)
{
var toBack = 0;
var temp = 0;
var unite = "";
for(var i=0;i < qjNum.length;i++)
{
toAscii=qjNum.charCodeAt(i);
toBack =toAscii-65248;
temp = String.fromCharCode(toBack);
unite = unite + temp ;
}
alert(unite);
return true;
}
if(toAscii > 47 && toAscii < 58 && qjNum.length == 11)
{
alert(qjNum);
return true;
}
else{
alert("請輸入正確的手機(jī)號碼");
document.myform.qjNum.value="";
return false;
}
}
// --></script>
</head>
<form name="myform" action="">
中文數(shù)字轉(zhuǎn)換成阿拉伯?dāng)?shù)字:<input type="text" id="qjNum" name="qjNum"/><input type="button" value="提 交" onclick="changeNum()"/>
</form>
</html>
這是個(gè)判斷手機(jī)號的問題!另外請注意我這還用到了jquery!記得引入哦……
相關(guān)文章
jQuery EasyUI NumberBox(數(shù)字框)的用法
jQuery EasyUI 數(shù)字框(NumberBox)用法2010-07-07
Jquery通過Ajax訪問XML數(shù)據(jù)的小例子
這篇文章主要介紹了Jquery通過Ajax訪問XML數(shù)據(jù),有需要的朋友可以參考一下2013-11-11
jquery中val()方法是從最后一個(gè)選項(xiàng)往前讀取的
這篇文章主要介紹了jquery中val()方法是從最后一個(gè)選項(xiàng)往前讀取的,需要的朋友可以參考下2015-09-09
jquery實(shí)現(xiàn)控制表格行高亮實(shí)例
jquery實(shí)現(xiàn)控制表格行高亮實(shí)例,需要的朋友可以參考一下2013-06-06
Jquery 選中表格一列并對表格排序?qū)崿F(xiàn)原理
該實(shí)現(xiàn)的主要思想是:獲取鼠標(biāo)點(diǎn)擊的表頭單元格的列號,遍歷數(shù)據(jù)行,獲取每個(gè)<tr>中的html,同時(shí)獲取每個(gè)<tr>標(biāo)簽下對應(yīng)獲取到的列號的<td>標(biāo)簽中的內(nèi)容,并取得<th>標(biāo)簽的type屬性值,需要的朋友可以了解下2012-12-12

