方向键 移动checkboxlist焦点

  http://www.cnblogs.com/zhangziqiu/archive/2009/04/30/jQuery-Learn-1.html  jquery

 series.SmartLabelStyle.Enabled = false;

$(function() {

        var baseIndex = 100;

        $("#tblGrid")

        .find("tr").each(function(r) {

            $(this).find("td").each(function(c) {

                $(this).find("input")

                .attr("tabindex", r * 100 + c + baseIndex)

                .addClass("cGridInput");

            });

        });

        $("#tblGrid .cGridInput").live("keydown", function(evt) {

            var tabIndex = parseInt($(this).attr("tabindex"));

            switch (evt.which) {

                case 38: //上

                    tabIndex -= 100;

                    break;

                case 40: //下

                    tabIndex += 100;

                    break;

                case 37: //左(會導致輸入時無法使用左右移)

                    tabIndex--;
                    break;

                case 39: //右(會導致輸入時無法使用左右移)

                    tabIndex++;

                    break;

                default:

                    return;

            }

            if (tabIndex > 0) {

                $(".cGridInput[tabindex=" + tabIndex + "]").focus();

                return false;

            }

            return true;

        });

    });

posted on 2012-07-09 23:56  木叶堂  阅读(158)  评论(0编辑  收藏  举报

导航