使用Firefox拖放不在TD中工作

时间:2014-04-15 14:02:15

标签: jquery firefox drag-and-drop

我已经为我的应用程序实现了拖放式架构,但它仅适用于IE和Chrome,它不能与Firefox一起使用...

HTML:

<table>
            <thead>
                <tr>
                    <th>test</th>
                    <th>test</th>
                    <th>test</th>
                    <th>test</th>
                    <th>test</th>
                    <th>test</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>0</td>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                    <td>4</td>
                    <td>5</td>
                </tr>
                <tr>
                    <td>6</td>
                    <td>7</td>
                    <td>8</td>
                    <td>9</td>
                    <td>10</td>
                    <td>11</td>
                </tr>
                <tr>
                    <td>12</td>
                    <td>13</td>
                    <td>14</td>
                    <td>15</td>
                    <td>16</td>
                    <td>17</td>
                </tr>
                            </tbody>
                  </table>

JS:

        $('td').on({
            dragstart: function(e) { onDragStart($(this)); },
            dragenter: function(e) { onDragEnter(e, $(this)); },
            dragleave: function(e) {},
            dragover: function(e) { e.preventDefault(); },
            drop: function(e) {},
            dragend: function(e) { onDragEnd(e); }
        });

        var onDragStart = function onDragStart($case){
            sessionStorage.setItem('draggableText', $case.text());
        };


        var onDragEnter = function onDragEnter(e, $case){
            $case.addClass('onDraggableElement');
            e.preventDefault();
        };

        var onDragEnd = function onDragEnd(e){
            e.stopPropagation();
            $('td[draggable="true"').removeClass('onDraggableElement');
        }

1 个答案:

答案 0 :(得分:1)

将DIV放入TD。使DIV可拖动,而不是表格单元格。