function ff()
{
document.getElementById("table1").outerHTML = "<table id=\"table1\" id=\"table1\"><tr><td>asdfklakds</td><td>sdi9934893</td></tr></table>";}

解决方案 »

  1.   

    The property is read/write for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR. The property has no default value.
      

  2.   

    用outerHTML,当第二次运行ff()时,显示"null为空或不是对象",To. stefli(潜心修炼,升级中....) 
    如果我在一个页面上是需要插入一个如
    <table>
    <tr class="mul_1"><td></td><td></td></tr>
    <tr class="mul_2"><td></td><td></td></tr>
    </table>,
    或者和这类似功能的..我该如何做?innerHTML对table只读,那么有什么方法可以变通?非常多谢指点.
      

  3.   

    呵,刚看到msdn上的一段.
    To change the contents of the table, tFoot, tHead, and tr elements, use the table object model described in How to Build Tables Dynamically. For example, use the IHTMLTableRow::rowIndex property or the rows collection to retrieve a reference to a specific table row. To retrieve a reference to a specific cell, use the IHTMLTableCell::cellIndex property or the cells collection. You can add or delete rows using the IHTMLTableRow::insertCell and IHTMLTableRow::deleteCell methods. To change the content of a particular cell, use the IHTMLElement::innerHTML property试试
      

  4.   

    好复杂~~~..<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML xmlns:MSHelp=http://msdn.microsoft.com/msHelp>
    <HEAD>
    <TITLE>Table Object Model Sample</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-8859-1">
    <META NAME="AUTHOR" CONTENT="InetSDK">
    <META NAME="MS.LOCALE" CONTENT="EN-US">
    <META NAME="ROBOTS" CONTENT="noindex"><!-- SAMPLE_STYLE_START -->
    <LINK REL="stylesheet" HREF="/msdn-online/shared/css/ie4.css" TYPE="text/css">
    <!-- SAMPLE_STYLE_END --><LINK REL="stylesheet" TYPE="text/css" HREF="ms-help://Hx/HxRuntime/HxLink.css"><STYLE TYPE="text/css">
    PRE.clsCode { font-size:110%; } 
    PRE.clsSyntax { font-size:100%; }  
    TD DIV.clsBeta { display:none;}
      MSHelp\:link {
        color:#0000ff;
        text-decoration:underline;
        cursor:hand;
        hoverColor:#3366ff;
        filterString: ;}
    </STYLE>
    </HEAD>
    <!--TOOLBAR_START-->
    <!--TOOLBAR_EXEMPT-->
    <!--TOOLBAR_END--><BODY TOPMARGIN=0 LEFTMARGIN=0 BGPROPERTIES="FIXED" BGCOLOR="#FFFFFF" LINK="#000000" VLINK="#808080" ALINK="#000000"><BLOCKQUOTE CLASS="body">
    <!-- CONTENTS_START -->
    <H1>Table Object Model Sample</H1><P>This sample demonstrates a table created with the Table Object Model.<BLOCKQUOTE>
    <TABLE ID="oTable" BORDER BGCOLOR="lightslategray">
    <TBODY ID="oTBody0"></TBODY>
    <TBODY ID="oTBody1"></TBODY>
    </TABLE>
    </BLOCKQUOTE><SCRIPT LANGUAGE="JScript">
    window.onload = fnInit;function fnInit()
    {
      // Declare variables and create the header, footer, and caption.
      var oTHead = oTable.createTHead();
      var oTFoot = oTable.createTFoot();
      var oCaption = oTable.createCaption();
      var oRow, oCell;
      var i, j;  // Declare stock data that would normally be read in from a stock Web site.
      var heading = new Array;  heading[0] = "Stock symbol";
      heading[1] = "High";
      heading[2] = "Low";
      heading[3] = "Close";  var stock = new Array;  stock["0,0"] = "ABCD";
      stock["0,1"] = "88.625";
      stock["0,2"] = "85.50";
      stock["0,3"] = "85.81";  stock["1,0"] = "EFGH";
      stock["1,1"] = "102.75";
      stock["1,2"] = "97.50";
      stock["1,3"] = "100.063";  stock["2,0"] = "IJKL";
      stock["2,1"] = "56.125";
      stock["2,2"] = "54.50";
      stock["2,3"] = "55.688";  stock["3,0"] = "MNOP";
      stock["3,1"] = "71.75";
      stock["3,2"] = "69.00";
      stock["3,3"] = "69.00";  // Insert a row into the header.
      oRow = oTHead.insertRow();
      oTHead.bgColor = "lightskyblue";  // Insert cells into the header row.
      for (i=0; i<4; i++)
      {
        oCell = oRow.insertCell();
        oCell.align = "center";
        oCell.style.fontWeight = "bold";
        oCell.innerText = heading[i];
      }  // Insert rows and cells into the first body.
      for (i=0; i<2; i++)
      {
        oRow = oTBody0.insertRow();
        for (j=0; j<4; j++)
        {
          oCell = oRow.insertCell();
          oCell.innerText = stock[i + "," + j];
        }
      }  // Set the background color of the first body.
      oTBody0.bgColor = "lemonchiffon";  // Insert rows and cells into the second body.
      for (i=2; i<4; i++)
      {
        oRow = oTBody1.insertRow();
        for (j=0; j<4; j++)
        {
          oCell = oRow.insertCell();
          oCell.innerText = stock[i + "," + j];
        }
      }  // Set the background color of the second body.
      oTBody1.bgColor = "goldenrod";  // Insert rows and cells into the footer row.
      oRow = oTFoot.insertRow();
      oCell = oRow.insertCell();
      oCell.innerText = "Quotes are for example only.";
      oCell.colSpan = "4";
      oCell.bgColor = "lightskyblue";  // Set the innerText of the caption and position it at the bottom of the table.
      oCaption.innerText = "Created using Table Object Model."
      oCaption.style.fontSize = "10";
      oCaption.align = "bottom";
    }
    </SCRIPT>
    <!-- CONTENTS_END --><!-- START_PAGE_FOOTER -->
    <BR><BR><BR>
    <MSHelp:link xmlns:MSHelp="http://msdn.microsoft.com/mshelp" keywords="msdn_copyright" TABINDEX="0">&copy; 2003 Microsoft Corporation. All rights reserved.</MSHelp:link>.
    <!-- END_PAGE_FOOTER -->
    </BLOCKQUOTE>
    </BODY>
    </HTML>