如何实现以下效果? 页面上点击一个按钮。添加一个TABLE或者TABLE中添加一行,并且TABLE或这行里面有一个TEXTBOX 和一个BUTTON? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用insertRow和insertCell,然后使用innerHtml也可以用document.createElement <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <title> New Document </title> <script type="text/javascript"> function add(){ var tb = document.getElementById("tb"); var tr = tb.insertRow(-1); var td = tr.insertCell(-1); var text = document.createElement("input"); text.type="text"; td.appendChild(text); td = tr.insertCell(-1); var button = document.createElement("input"); button.type="button"; button.value="Save"; td.appendChild(button); } </script> </head> <body> <input type="button" value="添加" onclick="add()" /> <table id="tb"> <th>text</th><th>button</th> </table> </body></html> <SCRIPT LANGUAGE="JavaScript">function getTD(){ var obj=document.getElementById("table1"); if(obj==null){ obj=document.createElement("table"); obj.id="table1"; document.body.appendChild(obj); } var row=obj.insertRow(); var cell=row.insertCell(); cell.innerHTML="<input><input type=button>";}</SCRIPT><input type=button value=getTD onclick="getTD();"> 以上两种方法,可以,但是加的是INPUT的控件,可不可以加第三方控件?〈ig:WebTextEditor ID='txtLink' runat='server' Width='100%'/> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>js测试</title><style></style><script src="jquery-1.3.2.js"></script><script>$(document).ready(function(){ $("#btn").click(function(){ $("#table").append("<tr>" +"<td><input type='button' value='点击'/></td>" +"<td><input type='checkbox'/></td>" +"<td>hello</td>" +"</tr>"); });});</script></head><body><table width="200" border="1" id="table"> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> <tr> <td>7</td> <td>8</td> <td>9</td> </tr></table><input type="button" id="btn" value="增加一行" /></body></html> LZ自己试试吧,俺也不知道你那控件好不好使…… <INPUT TYPE="button" VALUE="新建" ONCLICK="add()"> <TABLE id="tab"> <TR> <TH>textbox</TH> <TH>button</TH> </TR> </TABLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function add(){ var tab = document.getElementById("tab"); var newrow = tab.insertRow(); var newcell = newrow.insertCell(); newcell.innerHTML = "<ig:WebTextEditor ID='txtLink' runat='server' Width='100%'/>"; //newcell.innerHTML = '<INPUT TYPE="text" NAME="tbox">'; var newcell = newrow.insertCell(); newcell.innerHTML = '<INPUT TYPE="button" value="button">'; } //--> </SCRIPT> 使用LigerUi进行Layout的时候,发现left中怎么也去不掉上面的条框... 中文乱码问题 求解决 帮忙看一下,这个怎么回事? 动态数据如何排版???? javascript怎样获得<form>里的text的值 js获取当天是本月的第几个周四 求懂JS的帮忙看看数组的格式问题 在一个页面中如何传递变量的值? 用window.open()方法如何使新弹出的窗口最大化? 请问以下这段程序哪里有问题,为什么运行时,总是提示脚本有“缺少对象”的错误? 高手请进,阿赖实用javascript控件如何实现点击横向菜根节点超链接问题 我想实现点图片也能传值这里怎么修改呢!!!!
也可以用document.createElement
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
function add(){
var tb = document.getElementById("tb");
var tr = tb.insertRow(-1);
var td = tr.insertCell(-1);
var text = document.createElement("input");
text.type="text";
td.appendChild(text);
td = tr.insertCell(-1);
var button = document.createElement("input");
button.type="button"; button.value="Save";
td.appendChild(button);
}
</script>
</head> <body>
<input type="button" value="添加" onclick="add()" />
<table id="tb">
<th>text</th><th>button</th>
</table>
</body>
</html>
function getTD(){
var obj=document.getElementById("table1");
if(obj==null){
obj=document.createElement("table");
obj.id="table1";
document.body.appendChild(obj);
}
var row=obj.insertRow();
var cell=row.insertCell();
cell.innerHTML="<input><input type=button>";
}
</SCRIPT>
<input type=button value=getTD onclick="getTD();">
〈ig:WebTextEditor ID='txtLink' runat='server' Width='100%'/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js测试</title>
<style>
</style>
<script src="jquery-1.3.2.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#table").append("<tr>"
+"<td><input type='button' value='点击'/></td>"
+"<td><input type='checkbox'/></td>"
+"<td>hello</td>"
+"</tr>");
});
});
</script>
</head>
<body>
<table width="200" border="1" id="table">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
<input type="button" id="btn" value="增加一行" />
</body>
</html>
<TABLE id="tab">
<TR>
<TH>textbox</TH>
<TH>button</TH>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function add(){
var tab = document.getElementById("tab");
var newrow = tab.insertRow();
var newcell = newrow.insertCell();
newcell.innerHTML = "<ig:WebTextEditor ID='txtLink' runat='server' Width='100%'/>";
//newcell.innerHTML = '<INPUT TYPE="text" NAME="tbox">';
var newcell = newrow.insertCell();
newcell.innerHTML = '<INPUT TYPE="button" value="button">';
}
//-->
</SCRIPT>