由用户会输入全角字符,给查询带来不便,所以需要限制用户输入全角字符。
<INPUT name="CardId" onKeyUp="quanjiao(this);">
<script language="javascript">
function quanjiao(obj)
{
var str=obj.value;
if (str.length>0)
{
for (var i = str.length-1; i >= 0; i--)
{
unicode=str.charCodeAt(i);
if (unicode>65280 && unicode<65375)
{
alert("不能输入全角字符,请输入半角字符");
obj.value=str.substr(0,i);
}
}
}
}
本文介绍了一种方法,通过JavaScript限制用户在输入框中使用全角字符,以避免查询时带来的不便。当用户尝试输入全角字符时,将显示警告并移除最近输入的全角字符。
770

被折叠的 条评论
为什么被折叠?



