无法动态向 HTML 表添加行
我无法动态向 HTML 表添加行。我使用 IHtmlDocument2
创建 tr
和 td
元素,并使用 IHtmlElement
设置属性和 IHtmlDomNode
code> 将创建的节点添加到文档层次结构中。
请任何人帮助我解决上述问题。
当我获取 tr
标记时,我正在遍历文档,我已使用 CreateElement
创建了 tr
元素,然后使用 InsertBefore< /code> 将其插入到文档中,但它不起作用。
我已经尝试了一个星期,但没有任何效果。
I am unable to add a row to a HTML table dynamically. I am using IHtmlDocument2
to create tr
and td
elements and IHtmlElement
to set attributes and IHtmlDomNode
to add created node to the document hierarchy.
Please anyone help me to solve the above problem.
I am traversing through the document when I get the tr
tag I have created the tr
element using CreateElement
, then I use InsertBefore
to insert it into the document but it's not working.
I've tried for one week but didn't get anything working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您开始使用 JavaScript 框架,例如 jQuery 或 原型。无论您使用哪种浏览器,其中任何一个都允许您通过一行 JavaScript 代码实现该功能。使用原型例如:
I suggest that you start using a JavaScript framework such a jQuery or Prototype. Either of these will allow you to achieve the functionality with one line of JavaScript code regardless of which browser you have. Using Prototype for example:
有了 jQuery 就可以了
With jQuery it's
可能有点晚了。我最近更换了一个过去使用旧 DHTML 控件的 .Net 应用程序,但为了让它在 Windows 7 下工作,我不得不将其替换为 WebBrowser 控件,这代表了功能上的重大倒退。我一直在使用底层 IHtmlDocument2 接口来使用它。在这种情况下,我“作弊”,只是用原始 HTML 构建了表格,将其作为 HTML 粘贴到剪贴板,然后使用界面的 execCommand("Paste") 。它被包裹在剪贴板保护器内,因此原始剪贴板状态被恢复。
Probably a little late. I've been recently replacing a .Net app that used to use the old DHTML control, but to get it to work under Windows 7 I've had to replace this with the WebBrowser control which represents a significant step backward in functionality. I've been using the underlying IHtmlDocument2 interface to work with it. In this case I "cheated" and just built the table up in raw HTML, pasted it to the clipboard as HTML, then use execCommand("Paste") of the interface. This was wrapped within a clipboard preserver so the original clipboard state was restored.