有时候需要生成一些节点,我们可以利用JavaScript生成,在此展示生成表格的方法
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
mytr=document.createElement('tr');
mytd1=document.createElement('td');
mytd1.innerHTML='This is test';
mytr.appendChild(mytd1);
mytd2=document.createElement('td');
mytd2.innerHTML='This is test';
mytr.appendChild(mytd2);
mytr2=document.createElement('tr');
mytd3=document.createElement('td');
mytd3.innerHTML='This is test';
mytr2.appendChild(mytd3);
mytd4=document.createElement('td');
mytd4.innerHTML='This is test';
mytr2.appendChild(mytd4);
mytable=document.getElementsByTagName('table')[0];
// mytable=document.createElement('table');
mytable.appendChild(mytr);
mytable.appendChild(mytr2);
</script>
</head>
<body>
<table></table>
</body>
</html>