在表中创建一个新行 [英] create a new row in a table

查看:60
本文介绍了在表中创建一个新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好


有人可以帮助我在表格中创建动态内容吗?对于

示例,请参阅下面的javascript和html - 当我点击按钮时,为什么在表格中没有创建新行
? (我使用的是Internet Explorer 6)。


< html>

< head>

< title> TEST< ; / title>

< script language =" javascript">

function addField(){

alert(''添加字段'');

my_div.innerHTML = my_div.innerHTML +"< tr>< td> new row< / td>< / tr>" ;;

}

< / script>

< / head>


< body>

< table border =" 1">

< tr>

< td>

第一行

< / td>

< / tr>


< div id =" my_div">< / div>


< tr>

< td>

< input type =" button" value =" click me"

onclick =" javascript :addField()" >

< / td>

< / tr>

< / table>

< ; / body>

< / html>


谢谢,

彼得

Hi there

can someone please help me with creating dynamic content in a table? For
example, see the below javascript and html - why is a new row not created in
the table when I click the button? (I am using Internet Explorer 6).

<html>
<head>
<title>TEST</title>
<script language="javascript">
function addField() {
alert( ''Add Field'' );
my_div.innerHTML = my_div.innerHTML + "<tr><td>new row</td></tr>";
}
</script>
</head>

<body>
<table border="1">
<tr>
<td>
first row
</td>
</tr>

<div id="my_div"></div>

<tr>
<td>
<input type="button" value="click me"
onclick="javascript:addField()" >
</td>
</tr>
</table>
</body>
</html>

Thanks,
Peter

推荐答案

在文章< 41 ******** @ news.wineasy.se>," Peter Kirk" <彼得>启发我们

with ...
In article <41********@news.wineasy.se>, "Peter Kirk" <peter> enlightened us
with...
您好

有人可以帮助我在表格中创建动态内容吗?对于
示例,请参阅下面的javascript和html - 为什么单击按钮时表中没有创建新行? (我使用的是Internet Explorer 6)。


无效的HTML。


这也是制作动态表的一种可怕方式。 />
< / tr>

< div id =" my_div">< / div>


div不允许成为TBODY的孩子。

TBODY小时候只有TR。
http://www.w3.org/TR/REC- html40 / stru ... tml#edef-TBODY

<!ELEMENT TBODY OO(TR)+ - 表体 - >

< ; tr>
< td>
< input type =" button" value =" click me"
onclick =" javascript :addField()" >
Hi there

can someone please help me with creating dynamic content in a table? For
example, see the below javascript and html - why is a new row not created in
the table when I click the button? (I am using Internet Explorer 6).

Invalid HTML.

This is a horrible way to make dynamic tables, too.
</tr>

<div id="my_div"></div>
A div is not allowed to be the child of TBODY.
TBODY has only TR as a child.
http://www.w3.org/TR/REC-html40/stru...tml#edef-TBODY
<!ELEMENT TBODY O O (TR)+ -- table body -->

<tr>
<td>
<input type="button" value="click me"
onclick="javascript:addField()" >



onClick已经是脚本了。删除javascript :来自它的东西。

onClick =" addField()"


要制作动态表行,请使用createElement和appendChild。

创建元素,然后将其附加到TBODY。或者使用插入方法或

替换,如果您愿意的话。


-

-

~kaeli~

意志的定义?...(这是一个死的赠品。)
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace



onClick is already script. Drop the "javascript:" stuff from it.
onClick="addField()"

To make dynamic table rows, use createElement and appendChild.
Create the element, then append it to TBODY. Or use of the insert methods or
replace if you''d prefer that.

--
--
~kaeli~
The definition of a will?... (It''s a dead giveaway.)
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace


感谢您的回复...


" kaeli" < TI ****** @ NOSPAM.comcast.net> skrev i en meddelelse

新闻:MP ************************ @ nntp.lucent.com ...
Hi, thanks for the response...

"kaeli" <ti******@NOSPAM.comcast.net> skrev i en meddelelse
news:MP************************@nntp.lucent.com...
在文章< 41 ******** @ news.wineasy.se>," Peter Kirk" <彼得>开明
us
In article <41********@news.wineasy.se>, "Peter Kirk" <peter> enlightened us
有人可以帮助我在表格中创建动态内容吗?对于
示例,请参阅下面的javascript和html - 当我单击按钮时,为什么在表中创建的新行不是
? (我正在使用Internet Explorer 6。)
can someone please help me with creating dynamic content in a table? For
example, see the below javascript and html - why is a new row not created in the table when I click the button? (I am using Internet Explorer 6).



HTML无效。

这也是制作动态表格的一种可怕方式。



Invalid HTML.

This is a horrible way to make dynamic tables, too.




很可能......我知道关于javascript的zip,几乎拉链关于HTML ....



Quite likely.... I know zip about javascript, and almost zip about html....

< / tr>

< div id =" my_div">< / div>
</tr>

<div id="my_div"></div>



div不允许是TBODY的孩子。



A div is not allowed to be the child of TBODY.




好​​的 - 这就是你的意思,它是无效的 - 里面不允许DIV

a TABLE?不知道什么是DIV是的,只是认为这是一种方式来创建一个你可以从html中的其他地方引用的标签。


TBODY小时候只有TR。
http:// www.w3.org/TR/REC-html40/stru...tml#edef-TBODY
<!ELEMENT TBODY OO(TR)+ - 桌体 - >


什么是TBODY其实。它是否像TABLE?



OK - that''s what you mean by it being invalid - a DIV is not allowed inside
a TABLE? Don''t really know what a "DIV" is, just thought it was a way to
create a label you could reference from other places in the html.

TBODY has only TR as a child.
http://www.w3.org/TR/REC-html40/stru...tml#edef-TBODY
<!ELEMENT TBODY O O (TR)+ -- table body -->
What is "TBODY" actually. Is it like TABLE?


< tr>
< td>
< ; input type =" button" value =" click me"
onclick =" javascript :addField()" >

<tr>
<td>
<input type="button" value="click me"
onclick="javascript:addField()" >


:来自它的东西。
onClick =" addField()"

要制作动态表行,请使用createElement和appendChild。
创建元素,然后将其附加到TBODY。或者使用插入方法



onClick is already script. Drop the "javascript:" stuff from it.
onClick="addField()"

To make dynamic table rows, use createElement and appendChild.
Create the element, then append it to TBODY. Or use of the insert methods



或替换,如果您愿意的话。


or replace if you''d prefer that.




好​​的,谢谢。我现在有一个地方可以开始寻找。



OK thanks. I''ve got a place to start looking now.


在文章< 41 ****** @ news.wineasy.se>中,peter @ ciber开悟了我们用...
In article <41******@news.wineasy.se>, peter@ciber enlightened us with...

很可能....我知道关于javascript的zip,几乎拉链关于HTML ....


首先学习HTML。你永远不会编码体面的DHTML。

Quite likely.... I know zip about javascript, and almost zip about html....

Learn HTML first. You''ll never code decent DHTML until you do.
< / tr>

< div id =" my_div">< / div>
</tr>

<div id="my_div"></div>



div不允许是TBODY的孩子。



A div is not allowed to be the child of TBODY.



好的 - 这就是你无效的意思 - 一个桌子里面不允许DIV吗?不知道什么是DIV是的,只是认为这是一种创建标签的方法,你可以从html的其他地方引用。



OK - that''s what you mean by it being invalid - a DIV is not allowed inside
a TABLE? Don''t really know what a "DIV" is, just thought it was a way to
create a label you could reference from other places in the html.




不,HTML是一种结构化的布局语言。它有元素。元素具有

属性。

文档具有结构,并且该结构预先确定为一个点。

DIV是块级别元件。与P一样,SPAN不是块级元素。

表是一个表,因此,很多都有一定的结构。 TBODY是其中的一部分

,如果没有明确说明则暗示。


简而言之,这就是结构。 (允许使用更多的元素,但是现在这已经足够了。)




-THEAD

-TBODY

-TR

-TD

-你想要的东西,包括DIVS

-TFOOT


所以,你在代码中尝试做的是在div中添加一个表行。

这是不允许的。表格行只能是表格的子元素

头部,身体或脚部。



No, HTML is a structured layout language. It has elements. Elements have
attributes.
Documents have structure, and that structure is pre-determined to a point.
A DIV is a block-level element. As is P. SPAN is NOT a block-level element.
A table is a table, and as such, much have a certain structure. TBODY is part
of that and is implied if not explicitly stated.

This, in a nutshell, is the structure. (lots more elements are allowed, but
this is sufficient for now)

TABLE
-THEAD
-TBODY
-TR
-TD
-anything you want, including DIVS
-TFOOT

So, what you were trying to do in your code was append a table row to a div.
That''s not allowed. A table row can only be the child element of a table
head, body, or foot.

TBODY作为孩子只有TR。
http://www.w3 .org / TR / REC-html40 / stru ... tml#edef-TBODY
<!ELEMENT TBODY OO(TR)+ - 表体 - >
什么是" TBODY"其实。它是否像TABLE?
TBODY has only TR as a child.
http://www.w3.org/TR/REC-html40/stru...tml#edef-TBODY
<!ELEMENT TBODY O O (TR)+ -- table body -->
What is "TBODY" actually. Is it like TABLE?




不,它是桌子的主体。

THEAD是标题。

TFOOT是页脚。

好的,谢谢。我现在有一个地方可以开始寻找。



No, it''s the body of the table.
THEAD is the header.
TFOOT is the footer.

OK thanks. I''ve got a place to start looking now.




实际上,你应该先了解一下html。在开始创建

新元素之前,您需要知道哪些有效元素以及放置它们的位置。 :)


开始的好地方是在

comp.infosystems中请教好的教程。 www.authoring.html 。请先阅读他们的FAQ。他们对那里的那些东西很有帮助。


当你在那里的时候了解doctypes。


为了您的细读,这里有一个简单的版本,有效的HTML。注意

形式表单之外的元素不会提交(你的按钮),但是因为

这只是为了笑,所以没关系。另请注意,生产版本将在使用之前对对象和方法进行
测试。


<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN"

" http://www.w3.org/TR/REC-html40/loose.dtd">

< html>

< head>

< title> TEST< / title>

< script type =" text / javascript" >

函数addRow(){

var tbody = document.getElementById(" t1");

var newTr = document.createElement (TR);

var newTd = document.createElement(" TD");

var newTxt = document.createTextNode(" new row!" );

newTd.appendChild(newTxt);

newTr.appendChild(newTd);

tbody.appendChild(newTr);

}

< / script>

< / head>


< body>

< table border =" 1">

< tbody id =" t1"> ;

< tr>

< td>

第一行

< / td>

< / tr>

< tr>

< td>

< input type ="按钮" value =" click me"

onclick =" addRow()" >

< / td>

< / tr>

< / tbody>

< ; / table>

< / body>

< / html>


-

-

~kaeli~

针灸是一个很好的做法。
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace



Actually, you should really learn a bit more about html first. You need to
know what valid elements are and where to put them before you start creating
new ones. :)

A good place for you to start is to ask for good tutorials over in
comp.infosystems.www.authoring.html. Do read their FAQ first. They''re kinda
picky about that over there.

And learn about doctypes while you''re there.

For your perusal, here''s a simple version that works and is valid html. Note
that form elements outside a form will not submit (your button), but since
this is just for grins, it''s okay. Also note that a production version would
test for objects and methods before using them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>TEST</title>
<script type="text/javascript">
function addRow() {
var tbody = document.getElementById("t1");
var newTr = document.createElement("TR");
var newTd = document.createElement("TD");
var newTxt = document.createTextNode("new row!");
newTd.appendChild(newTxt);
newTr.appendChild(newTd);
tbody.appendChild(newTr);
}
</script>
</head>

<body>
<table border="1">
<tbody id="t1">
<tr>
<td>
first row
</td>
</tr>
<tr>
<td>
<input type="button" value="click me"
onclick="addRow()" >
</td>
</tr>
</tbody>
</table>
</body>
</html>

--
--
~kaeli~
Acupuncture is a jab well done.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace


这篇关于在表中创建一个新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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