这段创建表格代码出错在哪里???????????
<!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>
</head>
<style type="text/css">
</style>
<script type="text/javascript">
window.onload=function(){
var otable=$("tab"),otr=[];atext=[];
atext[0]=document.createTextNode("a");
atext[1]=document.createTextNode("b");
atext[2]=document.createTextNode("c");
atext[3]=document.createTextNode("d");
for(var j=0;j<4;j++){
otr[j]=otable.insertRow();
for(var i=0;i<atext.length;i++){
var otd=otr[j].insertCell(i);
otd.appendChild(atext[i]);
}
}
otable.style.border="solid red 1px;";
}
function $(a){
return document.getElementById(a);
}
</script>
<body>
<table id="tab">
</table>
</body>
</html>
------解决方案--------------------JScript code
window.onload = function() {
var otable = $("tab"),
otr = [];
atext = [];
atext[0] = document.createTextNode("a");
atext[1] = document.createTextNode("b");
atext[2] = document.createTextNode("c");
atext[3] = document.createTextNode("d");
for (var j = 0; j < 4; j++) {
otr[j] = otable.insertRow();
for (var i = 0; i < atext.length; i++) {
var otd = otr[j].insertCell(i);
otd.appendChild(atext[i].cloneNode(true)); //克隆一下
}
}
otable.style.border = "solid red 1px"; //属性值多了个分号
}
function $(a) {
return document.getElementById(a);
}
------解决方案--------------------
<body onload="a">改成
<body onload="a()">