伊图教程网[www.etoow.com]
http://www.etoow.com/html/2007-08/1186287640.html
然后处理相应需要处理的键盘消息。
这里随便处理几个必要的就可以了,因为文本框本身也不需要什么太多的用户操作,所以把光标的前移、后移、删除操作进行处理,这样你的文本框就有了基本的操作,现在操作起来已经很顺手了。
// 自行处理按钮
switch (nKeyCode)
{
case 8:// 如果动作是退格[<-]
{
strText = strText.substr(0,nCursorPos-1) + strText.substr(nCursorPos, nTextLen-nCursorPos);
nCursorPos--;
break;
}
case 46:// 如果动作是del[del]
{
strText = strText.substr(0,nCursorPos) + strText.substr(nCursorPos+1,nTextLen-nCursorPos-1);
nCursorPos--;
break;
}
case 38:// 如果动作是方向键[上]
case 39:// 如果动作是方向键[右]
{
nCursorPos++;
break;
}
case 37:// 如果动作是方向键[左]
case 40:// 如果动作是方向键[下]
{
nCursorPos--;
break;
}
default :
{
strText = strText.substr(0,nCursorPos) + String.fromCharCode(nKeyCode) + strText.substr(nCursorPos,nTextLen);
nCursorPos++;
if (nCursorPos>strText.length)
JavaScript在ASP中实现掩码文本框
'http://www.etoow.com/html/2007-08/1186287640.html