<html>
<body>
<div id="edit" align=center>
<table id="tab" border=1>
<tr align=center>
<td id="td1">1</td>
<td style="color:red" id="td2">2</td>
<td style="color:blue;font-size:18pt">3</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
</tr>
</table>
</div>
<script>
edit.contentEditable = true;
var DragDropSender=null;
var tab=document.getElementById("tab");
var rows=tab.rows;
for(var i=0;i<rows.length;i++){
var cells=rows[i].cells;
for(var j=0;j<cells.length;j++){
var td=cells[j];
td.ondrag=onDrag;
td.ondrop=onDrop;
}
}
function onDrag(){
DragDropSender=this;
}
function onDrop(){
this.style.color=DragDropSender.style.color;
this.style.fontSize=DragDropSender.style.fontSize;
}
</script>
</body>
</html>

解决方案 »

  1.   

    非常感谢!不过我看不懂,运行代码后,才知道你给的是我将要提的第二个问题,但不是只拖放一个单元格,所以我想知道的是:被一起选择的都有哪些单元格?
    this.style.color---给了我好提示,然而要是把<td onclick=tt()>中的onclick=tt()也复制过去又该如何??
      

  2.   

    <div id="edit" align=center>
    <table id="tab" border=1>
    <tr align=center>
    <td>1</td>
    <td style=color:red>2</td>
    <td style=color:blue;font-size:18pt>3</td>
    </tr>
    <tr onclick="s(this);">
    <td>1111</td>
    <td>2222</td>
    <td>3333</td>
    </tr>
    </table>
    </div><script>
    edit.contentEditable = true;
    function s(obj){
    if (obj.style.backgroundColor!='')
    {
    obj.style.backgroundColor='';
    }
    else
    {
    obj.style.backgroundColor='#f5f5f5';
    }
    }
    </script>也可以把onclick放td里.
      

  3.   

    然而要是把<td onclick=tt()>中的onclick=tt()也复制过去又该如何??
    也是一样~~~
    function onDrop(){
    this.style.color=DragDropSender.style.color;
    this.style.fontSize=DragDropSender.style.fontSize;
    this.onclick=DragDropSender.onclick;
    }选中2个再拖放,那怎么知道你要的是哪个的样式啊~~~?
      

  4.   

    我的想法是编辑如下表格:
        将 2、3 复制(或拖曳)到 1,即 2 占 1 的位置,3 占 2 的位置,
        同时连同他们的属性、动作等语句一起被复制,效果如同在word一样。
        而不是眼下的插入表格的现象。