用js怎样操作表格? 用js怎样操作表格? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 You can try Google or Baidu first 提问的智慧 用DOM例如:var FileList = $("idFileList"), oFragment = document.createDocumentFragment(); //用文档碎片保存列表 Each(rows, function(cells) { var row = document.createElement("tr"); Each(cells, function(o) { var cell = document.createElement("td"); if (typeof o == "string") { cell.innerHTML = o; } else { cell.appendChild(o); } row.appendChild(cell); }); oFragment.appendChild(row); }) 用文档对象模型创建结点,详情关注DOM创建与删除结点,关注document类 这有实例http://download.csdn.net/detail/qq307023807/3936431 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <body> <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <form id="form1" name="form1" action="" method="post"> <td> <table cellspacing="0" cellpadding="4" width="100%" border="0" > <tr> <td bgcolor="#C7E8F8"> <div align="center"><b>问题 1:</b> </div> </td> <td bgcolor="#C7E8F8"> <input size="60" name="Question1" onclick="alert(this.name)" onkeydown="if(event.keyCode==13) addNewQuestion()"> </td> </tr> </table> <div id="__idInsertBefore"></div> <input type="hidden" value="1" name="newTable"> <br/> <div align="right" style="padding:4px"> <input type=button onClick="addNewQuestion()" value="增加一个新问题" /> <input type="button" value="保存设置" > <input type="reset" value="重新设置" > </div> </td> </form> </tr></table><script>function addNewQuestion(){ document.form1.newTable.value = parseInt(document.form1.newTable.value) + 1; var newItemId; if( (document.form1.newTable.value).length > 2 ) { alert("您的调查问题总数不能超过 99 个。") window.location.reload(); } newItemId = document.form1.newTable.value; var objItem = '<table cellspacing="0" cellpadding="4" width="100%" border="0" >'; objItem += ' <tr>'; objItem += '<td bgcolor="#C7E8F8">'; objItem += ' <div align="center"><b>问题 ' + newItemId + ':</b> </div>'; objItem += ' </td>'; objItem += ' <td bgcolor="#C7E8F8">'; objItem += ' <input size="60" name="Question' + newItemId + '" onclick="alert(this.name)" onkeydown="if(event.keyCode==13) addNewQuestion()">'; objItem += ' </td>'; objItem += ' </tr>'; objItem += '</table>'; document.all.__idInsertBefore.insertAdjacentHTML("beforeBegin", objItem); document.form1.elements["Question" + newItemId].focus()}function showTips(obj){ obj.title = obj.value;}</script> </body></html> http://www.15ae.com/archive/2011-12/13113326472.htmljs 获得table表格的行和删除一行的方法 JS初级问题,输入的值在另一个页面被获取(不用jQuery实现) js视频20讲 JavaScript城市选择实例 浏览器后退之后,怎样保留之前JavaScript产生的效果 在图片上标注人脸框问题? javascript刷新父窗口 添加节点的问题, 郁闷了 问个很简单的问题 一段判断年份相同的JS代码,错在哪里呢? 麻烦麻烦,鱼与熊掌不可兼得。 不同系统之间WEB页面的交互! 如何去掉IE的自动搜索 js 怎样准确验证网址
提问的智慧
例如:
var FileList = $("idFileList"), oFragment = document.createDocumentFragment();
//用文档碎片保存列表
Each(rows, function(cells) {
var row = document.createElement("tr");
Each(cells, function(o) {
var cell = document.createElement("td");
if (typeof o == "string") { cell.innerHTML = o; } else { cell.appendChild(o); }
row.appendChild(cell);
});
oFragment.appendChild(row);
})
http://download.csdn.net/detail/qq307023807/3936431
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<form id="form1" name="form1" action="" method="post">
<td>
<table cellspacing="0" cellpadding="4" width="100%" border="0" >
<tr>
<td bgcolor="#C7E8F8">
<div align="center"><b>问题 1:</b> </div>
</td>
<td bgcolor="#C7E8F8">
<input size="60" name="Question1" onclick="alert(this.name)" onkeydown="if(event.keyCode==13) addNewQuestion()">
</td>
</tr>
</table>
<div id="__idInsertBefore"></div>
<input type="hidden" value="1" name="newTable">
<br/>
<div align="right" style="padding:4px">
<input type=button onClick="addNewQuestion()" value="增加一个新问题" />
<input type="button" value="保存设置" >
<input type="reset" value="重新设置" >
</div>
</td>
</form>
</tr>
</table>
<script>
function addNewQuestion()
{
document.form1.newTable.value = parseInt(document.form1.newTable.value) + 1;
var newItemId;
if( (document.form1.newTable.value).length > 2 )
{
alert("您的调查问题总数不能超过 99 个。")
window.location.reload();
}
newItemId = document.form1.newTable.value;
var objItem = '<table cellspacing="0" cellpadding="4" width="100%" border="0" >';
objItem += ' <tr>';
objItem += '<td bgcolor="#C7E8F8">';
objItem += ' <div align="center"><b>问题 ' + newItemId + ':</b> </div>';
objItem += ' </td>';
objItem += ' <td bgcolor="#C7E8F8">';
objItem += ' <input size="60" name="Question' + newItemId + '" onclick="alert(this.name)" onkeydown="if(event.keyCode==13) addNewQuestion()">';
objItem += ' </td>';
objItem += ' </tr>';
objItem += '</table>';
document.all.__idInsertBefore.insertAdjacentHTML("beforeBegin", objItem);
document.form1.elements["Question" + newItemId].focus()
}
function showTips(obj)
{
obj.title = obj.value;
}
</script> </body>
</html>