0
我在WebBrowser控件中動態創建HTML。除了表格外,大多數元素似乎都能正確顯示。以編程方式創建的表不會出現在WebBrowser控件中
我的代碼是:
var doc = webBrowser1.Document;
var body = webBrowser1.Document.Body;
body.AppendChild(webBrowser1.Document.CreateElement("hr"));
var div = doc.CreateElement("DIV");
var table = doc.CreateElement("TABLE");
var row1 = doc.CreateElement("TR");
var cell1 = doc.CreateElement("TD");
cell1.InnerText = "Cell 1";
row1.AppendChild(cell1);
var cell2 = doc.CreateElement("TD");
cell2.InnerText = "Cell 2";
row1.AppendChild(cell2);
table.AppendChild(row1);
div.AppendChild(table);
body.AppendChild(div);
body.AppendChild(webBrowser1.Document.CreateElement("hr"));
的HTML標籤的身體的outerHTML屬性是可見的,但出現在瀏覽器都是兩個水平規則。
如果我更換
div.AppendChild(table);
與
div.InnerHtml = table.OuterHtml
然後出現預期的一切。
你有沒有比較的源代碼,看看有什麼區別? – joerage 2009-11-19 17:13:55
感謝joerage - 我在表格內丟失了
- 我沒有意識到HTML和DOM之間存在差異。 – 2009-11-20 08:19:55回答
對於表的內容是可見的標籤必須是內< TBODY>
來源
2010-06-08 10:44:33 hultqvist
使用THEAD,TBODY TFOOT和元素
來源
2010-03-15 22:53:29 Answer
相關問題