日期:2014-05-16  浏览次数:20465 次

|zyciis| 如何让onkeypress 更改输入如输入 A就自动让他的ASCII码加1变成B
如:
 <input type="text" onkeypress="AsciiUp(this,event);" />
<script>
function AsciiUp(send,event)
{
  ????
}
</script>

谢谢

------解决方案--------------------
HTML code
<input type="text" onkeypress="return AsciiUp(this,event);" />
<script>
function AsciiUp(obj,e){
 var ev = window.event || e; 
 var cd = ev.keyCode || ev.charCode;
 if(cd >=65 && cd <90 || cd  >=97 && cd < 122) {
    ev.keyCode && (ev.keyCode = ev.keyCode+1);
    if(ev.charCode){
        obj.value=obj.value+String.fromCharCode(ev.charCode+1) ;
        return false;
    }
 }
}

------解决方案--------------------
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>测试</title>

<script type="text/javascript">
<!--
    function AsciiUp(event){
        var e = event || window.event;
        var code = e.keyCode || e.which;        
        if((64 < code && code <90) || (96 < code && code < 122)){
            code ++;
            var target = e.target || e.srcElement;
            target.value += String.fromCharCode(code);
            return false;
        }        
    }
//-->
</script>
</head>

<body>
    <input type="text" onkeypress="return AsciiUp(event)" />
</body>
</html>