0
  $(document).live('mouseup', function () { flag = false; });
            $(".csstablelisttd").live('mousedown', function (e)
            {

                $(".csstdselected").removeClass("csstdselected").addClass('csstdgreen');
                //This line gets the index of the first clicked row.
                lastRow = $(this).closest("tr")[0].rowIndex;
                var rowIndex = $(this).closest("tr").index();
                var colIndex = $(e.target).closest('td').index();
                $(".csstdhighlight").removeClass("csstdhighlight");


                //$('td:nth-child(' + colIndex + ')').addClass('csstdhighlight');

                //$(this).children(":gt(" + colIndex + ")").addClass("csstdhighlight");
                $(this).children(":not(:first)").addClass("csstdhighlight");
                e.preventDefault();
                flag = true;
                return false;
            });
            document.onmousemove = function () { return false; };
            $(".csstablelisttd").live('mouseenter', function (e)
            {
                // Compares with the last and next row index.
                currentRow = $(this).closest("tr")[0].rowIndex;
                if (lastRow == currentRow || lastRow == currentRow - 1 || lastRow == currentRow + 1)
                {
                    lastRow = $(this).closest("tr")[0].rowIndex;
                } else
                    return;

                if (flag)
                {


$(this).children(":not(:first)").addClass("csstdhighlight");
                        e.preventDefault();
                        if ($(".csstdhighlight").length >= 6)
                        {
                            //alert("Time slot not more than 45 minutes.");
                            flag = false;
                        }
                    }
                });

在我的表格中看到我有 8 列和 48 行我要做的用户只能开始拖动一列但超过 1 行

演示

4

1 回答 1

0

使用第 n 个子选择器:

$('td:nth-child(' + (colIndex + 1) + ')').addClass('foo');

是对您的 jsFiddle 的修改。

于 2012-10-22T13:40:52.557 回答