将整个表元素放在ASP:面板中 [英] Getting entire table element inside an ASP:panel

查看:64
本文介绍了将整个表元素放在ASP:面板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容:

I have the following:



< asp:panel id =myASPPanelrunat =server... />


<asp:panel id="myASPPanel" runat="server"... />





代码隐藏中有一些动态创建的表。假设有3个表,我们只想得到其中的一个,第一个。我们正在尝试使用Javascript。



我们有一个接收'myDiv'ID的函数。

然后我们可以获得表的数量并迭代它们。但是,当我们得到Table1时,我们只得到表中的CONTENTS,而不是tags / html / attributes等。



假设这是表:



MyTD





我们只能获得MyTD,而不是整张桌子。我们想要存储整个表格及其标签(就像上面输入的那样)并显示它。



我们注意到myDiv.getElementsByTagName('table ')。length工作(用于确定DIV中的表的数量),但是当我们想要将整个表存储在变量中时,我们这样做:myDiv.getElementsByTagName('table')[i] .innerHTML(this只给我们'MyTD'文本,不是标签,不是HTML,不是整个表元素及其属性),如果我们使用它:myDiv.getElementsByTagName('table')[i],屏幕上显示的是[object HTMLTableElement ]



我们如何获得整个表格及其HTML,属性,内联样式等?



谢谢。



我尝试过:





There are some dynamically created tables in the codebehind. Let's say there are 3 tables and we only want to get 1 of them, the first one. We are trying to do this using Javascript.

We have a function that RECEIVES the 'myDiv' ID.
We are then able to get the number of tables and iterate through them. However, when we get Table1, we only get the CONTENTS INSIDE the table, not the tags/html/attributes, etc.

Let's say this is the table:

MyTD


We are only able to get "MyTD", NOT the entire table. We want to store the entire table, along with its tags (just as it has been typed above) and display it.

We noticed that myDiv.getElementsByTagName('table').length works (for determining the number of tables inside of the DIV), but when we want to store the entire table in a variable, we do this: myDiv.getElementsByTagName('table')[i].innerHTML (this only gives us the 'MyTD' text, not tags, not HTML, not entire table element and its attributes) and if we use this: myDiv.getElementsByTagName('table')[i], what shows on the screen is [object HTMLTableElement]

How can we get the entire table along with its HTML, attributes, in-line style, etc?

Thank you.

What I have tried:

myDiv.getElementsByTagName('table')[i].innerHTML




myDiv.getElementsByTagName('table')[i]

推荐答案

innerHTML 属性返回指定元素的开始和结束标记之间的HTML - 内部HTML。 />


要获取包含开始和结束标记的HTML - 外部HTML - 请使用 outerHTML [ ^ ]属性。

The innerHTML property returns the HTML between the opening and closing tags of the specified element - the "inner" HTML.

To get the HTML including the opening and closing tags - the "outer" HTML - use the outerHTML[^] property.
myDiv.getElementsByTagName('table')[i].outerHTML


这篇关于将整个表元素放在ASP:面板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆