我想把下面的函数按“abc”执行“alert("hello world!")”,请问怎么做?
按键代码如下:
a:97  b:98   c:99
<body>
<script type="text/javascript" src="http://localhost/leb/auto/js/jquery-latest.js"></script>
<script>
window.onload= function(){
$(document).keypress(function(e){
if (e.which==97){
alert("hello world!"); //如果按a,就弹出hello world
}
})
}
</script>
<div id="test">1111</div>
</body>

解决方案 »

  1.   

    先用一个东西记住了你按得3个键是什么,然后再对比一下,是abc就弹出alert
      

  2.   


     <script type="text/javascript" src="http://localhost/leb/auto/js/jquery-latest.js"></script>    <script>
    var apressed , bpressed , cpressed;        window.onload= function(){
                $(document).keydown(function(e){
                    if (e.which==65) apressed = true;
                    if (e.which==66) bpressed = true;
                    if (e.which==67) cpressed = true;
                    if (apressed && bpressed && cpressed){
                        alert("hello world!");
                    }
                 })
                $(document).keyup(function(e){
                 apressed = bpressed = cpressed = false;
                })        }
        </script>
      

  3.   

    我在firefox 3.0下测试,两位的方法无效。
      

  4.   

    回帖发错地方的,sorry。原想回复是这里的问题http://topic.csdn.net/u/20090801/20/250c5587-7a4f-46cc-890f-942c67534660.html顺带:
    hokee哥,你的代码在firefox下测试无效,怎么回事?在fiefox下按键代码是 a:97  b:98  c:99 ,改过来也没用
      

  5.   

    ho0kee哥,能不能帮我解决这个问题:
    javascript怎样把所有[color=#FF6600]script标签移动到body最后面?[/color]
    链接:http://topic.csdn.net/u/20090802/18/ea082e0c-dc6d-4a25-ba22-9b5d78715cfb.html
    貌似jquery 无法操作script标签,欲哭无泪。