var tbody = document.createElement("TBODY");
tbody.appendChild(row);
tab.appendChild(tbody);
document.getElementById("grid").appendChild(tab);
tbody.appendChild(row);
tab.appendChild(tbody);
document.getElementById("grid").appendChild(tab);
解决方案 »
- jquery ajax如何获取html里div为mydiv里的内容?
- 在js文件里引入其他js文件问题,谢谢!
- Ext 中将后台id的值传给window组件中TabPanel怎么做?
- 急!!关于如何在JavaScript中检测信息不通过阻止页面向服务器回发
- js怎样实现frame框架的页面刷新!
- js引用js文件,显示的内容位置不对
- 怎样通过正则表达式 将“[ S]”替换成“”
- 关于jquery遍历json的问题
- 400分求使用knockout.js建立一个输入表单以及简单功能的完整代码,急!急!急!请大神们帮助!
- 为什么用src引入.js文件总会出现问题呢?
- 简单问题
- 如个通过已有的数据生成表格显示出来.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function() {
var tab=document.createElement("table");
mytablebody = document.createElement("tbody");
tab.border=1;
var row=document.createElement("tr");
var cell=document.createElement("td");
var input=document.createElement("input");
input.onclick=function(){alert('aaaa');}
input.value="aaaa";
cell.appendChild(input);
row.appendChild(cell);
mytablebody.appendChild(row);
tab.appendChild(mytablebody); document.getElementById("grid").appendChild(tab);
}
function add() {
var tab=document.getElementById("grid").children[0];
var row=tab.insertRow();
var cell=document.createElement("td");
var input=document.createElement("input");
input.onclick=function(){alert('bbbb');}
input.value="bbbb";
cell.appendChild(input);
row.appendChild(cell);
//为什么添加一行后alert()没有效果
}
</script>
</head><body>
<div id="grid"></div>
<input type="button" name="Submit" value="添加" onclick="add()"/>
</body>
</html>
应该 input.onclick=function(){alert("aaaa");}
<!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>无标题文档</title>
<script>
window.onload = function(){
var tab=document.createElement("table");
tab.border=1;
var tbd=document.createElement("tbody");
var row=document.createElement("tr");
var cell=document.createElement("td");
var input=document.createElement("input");
input.onclick="alert('aaaa')";
input.value="aaaa";
cell.appendChild(input);
row.appendChild(cell);
tbd.appendChild(row);
tab.appendChild(tbd);
document.getElementById("grid").appendChild(tab);
}
function add(){
var tab=document.getElementById("grid").childNodes[0];
var row=tab.insertRow(tab.rows.length);
var cell=document.createElement("td");
var input=document.createElement("input");
input.onclick="alert('bbbb')";
input.value="bbbb";
cell.appendChild(input);
row.appendChild(cell);
}
</script>
</head><body>
<div id="grid"></div>
<input type="button" name="Submit" value="添加" onclick="add()"/>
</body>
</html>
input.onclick=function(){alert("aaaa");}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function() {
var tab=document.createElement("table");
tab.border=1;var row=document.createElement("tr");
var cell=document.createElement("td");
var input=document.createElement("input");
input.onclick="alert('aaaa')";
input.value="aaaa";
cell.appendChild(input);
row.appendChild(cell);
tab.appendChild(row);
document.getElementById("grid").innerHTML=tab.outerHTML;
}
function add() {
var tab=document.getElementById("grid").children[0];
var row=tab.insertRow();
var cell=document.createElement("td");
var input=document.createElement("input");
input.onclick=function(){alert('bbbb');};
input.value="bbbb";
cell.appendChild(input);
row.appendChild(cell);
//为什么添加一行后alert()没有效果
}
</script>
</head><body>
<div id="grid"></div>
<input type="button" name="Submit" value="添加" onclick="add()"/>
</body>
</html>