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

就是用键盘敲击啊,就有一个超链接能够出现点击的效果,(触发onclick),请问高手该如何写代码?
如题

------解决方案--------------------
JScript code

<html>
<head>
    <script src="jquery-1.4.4.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            onkeydown = function (event) {
                if (event.keyCode == 65) {                   
                    var a = document.getElementById("a");                        
                    a.click(); 
                }
                if (event.keyCode == 66) {
                    var b = document.getElementById("b");
                    b.click();
                }
                if (event.keyCode == 67) {
                    var c = document.getElementById("c");
                    c.click();
                }

            }
        })
    </script>
</head>
<body>
    <div>
     <a id="a" href="http://www.baidu.com">A</a>
<a id="b" href="http://tieba.baidu.com">B</a>
<a id="c" href="http://mp3.baidu.com">C</a>
<a id="d">D</a>
<a id="e">E</a>
    </div>
</body>
</html>

------解决方案--------------------
JScript code

<html>
<head>
    <script type="text/javascript">
        window.onload = function () {          
            onkeydown = function (event) {
                if (event.keyCode == 65) {
                    var a = document.getElementById("a");
                    a.click();
                }
                if (event.keyCode == 66) {
                    var b = document.getElementById("b");
                    b.click();
                }
                if (event.keyCode == 67) {
                    var c = document.getElementById("c");
                    c.click();
                }
            }
        }
          
            
    </script>
</head>
<body  >
    <div>
     <a id="a" href="http://www.baidu.com">A</a>
<a id="b" href="http://tieba.baidu.com">B</a>
<a id="c" href="http://mp3.baidu.com">C</a>
<a id="d">D</a>
<a id="e">E</a>
    </div>
</body>
</html>

------解决方案--------------------
HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type="text/javascript">
window.onload = function() {
    
    document.body.onkeydown = function(e) {
        e = e || window.event;
        // 把键值转换成字母
        var key = String.fromCharCode(e.keyCode); 
        var dom = document.getElementById(key);
        if(dom) {
            dom.click();
        }
    }
}
</script>
</HEAD>
<BODY>

    <a id="A" onclick="alert('I am a')">A</a>
    <a id="B" onclick="alert('I am b')">B</a>
    <a id="C" onclick="alert('I am c')">C</a>
    <a id="D" onclick="alert('I am d')">D</a>
    <a id="E" onclick="alert('I am e')">E</a>

</BODY>
</HTML>