RSS订阅优然探索
你的位置:首页 » 技术文章 » 正文

回车移动到下一行同一个列控件下

选择字号: 超大 标准 发布时间:2011-3-31 15:26:9 | 作者:admin | 0个评论 | 人浏览

<script type="text/javascript">
function $3(id) {
    return document.getElementById(id);
}
document.onkeydown = function enterToTab() {

    //case 38: objUp();break;
    //case 40: objDown();break;
    //case 37: objLeft();break;
    //case 39: objRight();break;
    var moveType = 0;

    switch (event.keyCode) {
    case 38:
        moveType = 1;
        break
    case 40:
        moveType = 2;
        break
    case 13:
        moveType = 2;
        event.keyCode = 40;
        break
    case 37:
        moveType = 3;
        break
    case 39:
        moveType = 4;
        break
    default:
        moveType = 0;
        break
    }

    //文本才相应移动事件
    if (event.srcElement.type == "text") {
        var name = event.srcElement.id;
        //上下移动
        if (moveType == 1 || moveType == 2) {
            moveUpdown(name, moveType);
        }
        //左右移动
        if (moveType == 3 || moveType == 4) {
            moveLeftRight(name, moveType);
        }
    }
}

//左右移动
function moveLeftRight(name, moveType) {
    //gvInfo_ctl23_TextBox1
    var mInfo;
    var oldID;
    oldID = name.substring(name.length - 1, name.length);

    var newID;
    newID = (oldID);
    if (moveType == 3) {
        newID--;
    } else {
        newID++;
    }

    if (newID <= 0) {
        newID = 5
    }
    if (newID >= 6) {
        newID = 1
    }
    var newName = name.substring(0, name.length - 1) + newID;
    var m = $3(newName);
    if (m != null) {
        m.focus();
        m.select();
    }

}

//上下移动
function moveUpdown(name, moveType) {
    var mInfo;
    mInfo = name.split("_");
    var oldID = mInfo[1];
    oldID = oldID.substring(3, oldID.length);
    var newID;
    newID = (oldID);
    if (moveType == 1) {
        newID--;
    } else {
        newID++;
    }
    var newName;

    if (newID < 10) {
        newName = mInfo[0] + "_ctl0" + newID + "_" + mInfo[2];
    } else {
        newName = mInfo[0] + "_ctl" + newID + "_" + mInfo[2];

    }
    var m = $3(newName);

    if (m == null) {

        newName = mInfo[0] + "_ctl02_" + mInfo[2];
        m = $3(newName);
    }

    if (m != null) {
        m.focus();
        m.select();
    }

}
</script>

标签:

猜你喜欢

发表评论

必填

选填

选填

必填,不填不让过哦,嘻嘻。

记住我,下次回复时不用重新输入个人信息

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。