1. Check out our companion app, Forums for Android! Download from Google Play

Problem to get arrow keys in Javascript

Discussion in 'Application Development' started by jia2001, Sep 17, 2009.

  1. jia2001

    jia2001 New Member
    Thread Starter
    5

    Sep 17, 2009
    1
    0
    5
    It can't get the arrow keys with the following javascript in Browser in Android. But it works in Chrome on PC. if anyone has a solution? many thanks.


    <style>
    tr.highlight{
    background:#08246B;
    color:white;
    }
    </style>
    <table border="1" width="70%" id="ice">
    <tr><td>123</td>
    <td>234</td>
    <td>abc</td>
    <td>def</td></tr>
    <tr><td>123</td>
    <td>234</td>
    <td>abc</td>
    <td>def</td></tr>
    <tr><td>123</td>
    <td>234</td>
    <td>abc</td>
    <td>def</td></tr>
    <tr><td>123</td>
    <td>234</td>
    <td>abc</td>
    <td>def</td></tr>
    <tr><td>123</td>
    <td>234</td>
    <td>abc</td>
    <td>def</td></tr>
    </table>

    <script language="javascript">
    <!--
    var currentLine = -1;
    document.onkeydown = function (e)
    {
    e = window.event || e;
    switch (e.keyCode)
    {
    case 38:
    currentLine--;
    changeItem();
    break;
    case 40:
    currentLine++;
    changeItem();
    break;
    default :
    break;
    }
    }

    function changeItem()
    {
    if( document.all )
    var it = document.getElementById("ice").children[0];
    else
    var it = document.getElementById("ice");
    for (i=0;i<it.rows.length;i++)
    {
    it.rows.className = "";
    }
    if (currentLine < 0)
    currentLine = it.rows.length - 1;
    if (currentLine == it.rows.length)
    currentLine = 0;
    it.rows[currentLine].className = "highlight";
    }

    //-->
    </script>
     

    Advertisement

Share This Page

Loading...