一个棘手的HTML表单创建新表 [英] A trickier HTML Form create new table(s)

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

问题描述

嘿伙计们,我坚持的另一部分计划是创建一个电子邮件存储/参考系统。我需要第一行保存基本信息,从地址等,然后第二行将消息和任何注释存储在文本框中。我遇到的问题是我把两个放在不同的表中,所以当添加一个新行时,它会添加到它们中。是否可以这样做,例如在第二个添加中将它附加到底部表格?


我到| |来自| |日期| |主题|

|消息| | onClick()|


哪个会去


我要| |来自| |日期| |主题|

|消息|

我到| |来自| |日期| |主题|

|消息| | onClick()|


等等。这是我到目前为止的代码....


[HTML]< html>

< head>

< script type =" text / javascript">

function removeRowFromTable()

{

var tbl = document.getElementById(''myTable'');

var lastRow = tbl.rows.length;

if(lastRow> 2)tbl.deleteRow(lastRow - 1 );


var tbl1 = document.getElementById(''myTable1'');

var lastRow1 = tbl1.rows.length;

if(lastRow1> 2)tbl1.deleteRow(lastRow1 - 1);

}

< / script>




< script type =" text / javascript">


函数doThis()

{


var myTab = document.getElementById(''myTable'');

var row = myTab.rows.length;

var y = myTab.insertRow(row);


var a = y.insertCell(0);

var xx = document.createElement(''input'');

xx.type =" text";

xx.name =" EmailFrom []" ;;

a.appendChild(xx);


var b = y.insertCell(1);

var xx = document.createElement(''input'');

xx.type =" text";

xx.name =" EmailTo []" ;;

b.appendChild(xx);


var c = y.insertCell(2);

var xx = document.createElement(''input'');

xx.type =" text";

xx.name =" EmailDate []" ;;

c.appendChild(xx);


var d = y.insertCell(3);

var xx = document.createElement(''input'');

xx.type =" text";

xx.name =" EmailSubject []" ;;

d.appendChild(xx);


var myTab1 = document.getElementById(''myTable1'');

var row1 = myTab1.rows.length;

var z = myTab1.insertRow(row1);


var e = z.insertCell(0);

var xx = document.createElement(''textarea'');

xx.col =" 200"

xx.rows =" 5"

xx.name =" Message []" ;;

e.appendChild(xx);

}

< / script>


< / head>

< body>

< br />

< input type =" button"值= [新增" onclick =" doThis()">

< input type =" button"值= [移除" onClick =" removeRowFromTable()">

< br />

< table id =" myTable"边界=" 1 QUOT; CELLSPACING = QUOT; 5英寸cellpadding =" 5">

< tr>

< th>来自< / th>

< th> To< ; / th>

< th>日期< / th>

< th>主题< / th>

< / tr> ;

< table id =" myTable1"边界=" 1 QUOT; CELLSPACING = QUOT; 5英寸cellpadding =" 5">

< tr>

< th>消息< / th>

< / tr>

< / table>

< / table>

< / body>

< / html> [/ HTML]



任何帮助非常感谢

Hey guys, another part of program I am stuck at is to create an email storage / reference system. I need the first line to hold the basic info, from to address etc and then a second row to store the message and any comments in a text box. The problem I am having is that I put the two into different tables so when a new line is added it adds to both them. Is it possible to do this e.g to have on the second add to append it to the bottom table?

I To | | From | | Date | | Subject |
| Message | | onClick() |

Which would go to

I To | | From | | Date | | Subject |
| Message |
I To | | From | | Date | | Subject |
| Message | | onClick() |

And so on. Here is the code i have so far ....

[HTML]<html>
<head>

<script type="text/javascript">
function removeRowFromTable()
{
var tbl = document.getElementById(''myTable'');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);

var tbl1 = document.getElementById(''myTable1'');
var lastRow1 = tbl1.rows.length;
if (lastRow1 > 2) tbl1.deleteRow(lastRow1 - 1);
}
</script>



<script type="text/javascript">

function doThis()
{

var myTab = document.getElementById(''myTable'');
var row=myTab.rows.length;
var y=myTab.insertRow(row);

var a=y.insertCell(0);
var xx= document.createElement(''input'');
xx.type="text";
xx.name="EmailFrom[]";
a.appendChild(xx);

var b=y.insertCell(1);
var xx= document.createElement(''input'');
xx.type="text";
xx.name="EmailTo[]";
b.appendChild(xx);

var c=y.insertCell(2);
var xx= document.createElement(''input'');
xx.type="text";
xx.name="EmailDate[]";
c.appendChild(xx);

var d=y.insertCell(3);
var xx= document.createElement(''input'');
xx.type="text";
xx.name="EmailSubject[]";
d.appendChild(xx);


var myTab1 = document.getElementById(''myTable1'');
var row1=myTab1.rows.length;
var z=myTab1.insertRow(row1);

var e=z.insertCell(0);
var xx= document.createElement(''textarea'');
xx.col="200"
xx.rows="5"
xx.name="Message[]";
e.appendChild(xx);
}
</script>

</head>
<body>
<br/>
<input type="button" value="Add" onclick="doThis()">
<input type="button" value="Remove" onClick="removeRowFromTable()">
<br/>
<table id="myTable" border="1" cellspacing="5" cellpadding="5">
<tr>
<th>From</th>
<th>To</th>
<th>Date</th>
<th>Subject</th>
</tr>
<table id="myTable1" border="1" cellspacing="5" cellpadding="5">
<tr>
<th>Message</th>
</tr>
</table>
</table>
</body>
</html>[/HTML]


Any help much appreciated

推荐答案

第二个表已经(错误地)嵌套在第一个表格中。


发布代码时请使用代码标签。请参阅如何提出问题
The second table has been (incorrectly) nested in the first.

Please use code tags when posting code. See How to ask a question.


我很抱歉这个论坛相当新,但将来我会发帖询问如何...


关于你所说的你做的事意味着你不能嵌套这样的表,或者我已经错误地嵌套了它但它可以工作。


你对此有何看法?
my apologies im fairly new to this forum but in future i will post with regards to the "how to..."

In relation to what you said do you mean that you cannot nest tables like this or that I have nested it wrongly but it can work.

what are your thoughts on this?


我没有测试过你的代码,但我注意到myTable1在一行之后嵌套在myTable中,但不在表格单元格内。你的意思是嵌套这样的表还是应该在主表之外?
I haven''t tested your code, but I noticed that myTable1 is nested inside myTable after a row, but not inside a table cell. Did you mean to nest tables like that or was it supposed to be outside the main table?


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

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