我要实现的功能如下:
在一个表格的单元格中单击,插入一张图片(不是改变单元格背景),图片带一个超级连接.
如果再单击一个单元格,那么前面单击过的单元格恢复空白原样.

解决方案 »

  1.   

    try this  :<td onclick="aa(this)">var aa = function (obj){
     this.innerHTML = "<img src=''>";} 
      

  2.   

    <style>
    #tab{
        border:0px;
        border-collapse:collapse;.
    }
    #tab td{
        height:50px;
        width:50px;
        border:1px solid red;
        cursor:hand;
    }
    </style>
    <script>
    window.table_img_src="http://www.csdn.net/CSDN_Common_Header_Footer/Images/BiaoShi.gif";
    window.table_img_link="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010";
    window.onload=function(){
        var tab=document.getElementById("tab");
        window.tab=tab;
        var cells=tab.getElementsByTagName("td");
        for(var i=0;i<cells.length;i++){
            cells[i].onclick=cell_onclick;
        }
    }
    function cell_onclick(){
        if(window.tab.focus_cell)window.tab.focus_cell.innerHTML="";
        window.tab.focus_cell=this;
        var img = document.createElement("img");
        img.src=window.table_img_src;
        var link = document.createElement("a");
        link.href=window.table_img_link;
        link.appendChild(img);
        this.appendChild(link);
    }
    </script>
    <table id="tab">
    <tr><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td></tr>
    </table>
      

  3.   

    if(window.tab.focus_cell)window.tab.focus_cell.innerHTML="";
    前面加一句:
    if(window.tab.focus_cell==this)return;不然会有bug~~