社区
JavaScript
帖子详情
老问题了
lhdjk
2004-11-01 10:45:32
<table>
<tr><th>var1</th><th>var2</th></tr>
<tr><td><input></td><td><input></td></tr>
当在td最后一个input中输入信息并按下回车后,增加一行
...全文
101
6
打赏
收藏
老问题了
var1var2 当在td最后一个input中输入信息并按下回车后,增加一行
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
ttyp
2004-11-01
打赏
举报
回复
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
function addRow(src){
//alert(src);
var newrow = src.insertRow(src.rows.length-1);
newrow.height=20;
var i=4;
while(i--){
var newcell = newrow.insertCell();
switch(i){
case 0: newcell.innerHTML= '<input type="button" onClick="javascript:delRow(this.parentElement.parentElement)" value="删除此行">';break;
default: newcell.innerHTML=div1.innerHTML;break;
}
}
newrow.cells[0].children[0].focus();
}
function delRow(src){
var tab=src.parentElement;
var i=tab.rows.length;
while(i--){
if(src==tab.rows[i]){
alert("就是这行----"+ i);
tab.deleteRow(i);
}
}
}
function nextRow(obj)
{
if(event.keyCode==13)
{
if(obj.cellIndex != 2)
{
event.keyCode = 9;
}
else
{
addRow(obj.parentElement.parentElement);
}
}
}
</script>
</head>
<body>
<table id="tb" width="100%" border="1" align="center" cellpadding="1" cellspacing="1" style="border-collapse:collapse" bordercolor="#111111">
<tr>
<th scope="col" width="25%">奶类</th>
<th scope="col" width="25%">数量</th>
<th scope="col" width="25%">总重</th>
<th scope="col" width="25%">单价</th>
</tr>
<tr id="blankRow" onClick="addRow(this.parentElement)">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<div id="div1" style="display:none "><input id="txt" type="text" style="width:97%; background-color:#FFFFEF" onkeydown="javascript:return nextRow(this.parentElement)"></div>
</body>
</html>
突击召唤师
2004-11-01
打赏
举报
回复
-__- grammar
突击召唤师
2004-11-01
打赏
举报
回复
This is only a example, just to tell you that your problem can be solved in this way. It is very easy to modify it by yourself, isn't it?
lhdjk
2004-11-01
打赏
举报
回复
师兄,你的两个我都试了,我在table的tr中多加一个<td><input></td>,代码还是在第一个input得到回车后,就换行了。显然还需要改进呀,谢谢
突击召唤师
2004-11-01
打赏
举报
回复
<table>
<tr><td><input onkeypress="addNewLine(this)"></td></tr></table>
<script>
function addNewLine(it) {
if (event.keyCode == 13) {
var thisLine = it;
while (thisLine.tagName != "TR") {
thisLine = thisLine.parentNode;
}
var newLine = thisLine.cloneNode(true);
var inputbox = newLine.firstChild.firstChild
inputbox.value = "";
thisLine.parentNode.appendChild(newLine);
inputbox.focus();
//----------forbid event for other line---
it.onkeypress = null
//----------------------------------------
}
}
</script>
突击召唤师
2004-11-01
打赏
举报
回复
<table>
<tr><td><input onkeypress="addNewLine(this)"></td></tr></table>
<script>
function addNewLine(it) {
if (event.keyCode == 13) {
var thisLine = it;
while (thisLine.tagName != "TR") {
thisLine = thisLine.parentNode;
}
var newLine = thisLine.cloneNode(true);
var inputbox = newLine.firstChild.firstChild
inputbox.value = "";
thisLine.parentNode.appendChild(newLine);
inputbox.focus();
}
}
</script>
相关推荐
领导_不要再问这样的
问题
了.docx
领导_不要再问这样的
问题
了.docx
手机游戏降低游戏延迟的软件_《和平精英》手游怎么降低网络延迟 降低网络延迟的方法攻略...
导读《和平精英》手游中有很多的小伙伴们都比较好奇怎么才能快速解决网络延迟的
问题
了,用什么方法才可以解决的了网络延迟的
问题
了,有几种方法才可以解决网络延迟的
问题
了,相信这些都是各位小伙伴们都比较想知道的
问题
...《和平精英》手游中有很多的小伙伴们都比较好奇怎么才能快速解决网络延迟的
问题
了,用什么方法才可以解决的了网络延迟的
问题
了,有几种方法才可以解决网络延迟的
问题
了,相信这些都是各位小伙伴们都比较想...
跨域、this指向
不要再问我跨域的
问题
了: https://segmentfault.com/a/1190000015597029?utm_source=tag-newest 不要再问我this的指向
问题
了: https://segmentfault.com/a/1190000015438195 不要再问我移动适配的
问题
了: https://segmentfault.com/a/...
王爽的汇编语言学习后,很多
问题
就不再是
问题
了。
王爽的汇编语言学习后,很多
问题
就不再是
问题
了。
Linux移植随笔:终于解决Tslib的
问题
了
Linux移植随笔:终于解决Tslib的
问题
了
发帖
JavaScript
JavaScript
Web 开发 JavaScript
复制链接
扫一扫
8.7w+
社区成员
22.4w+
社区内容
Web 开发 JavaScript
社区管理员
加入社区
获取链接或二维码
帖子事件
创建了帖子
2004-11-01 10:45
社区公告
暂无公告