0

我需要write()使用 JavaScript 打印 html 表格的功能,列名应该是名字,姓氏和电子邮件顺序。我无法在表格中打印名称。不知道我做错了什么。下面是我的代码

<!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=iso-8859-1" />
<title>Address Book</title>


<script type="text/javascript">
function addressBookItem (fname, lname, email) {
    this.fname= fname;
    this.lname = lname; 
    this.email = email;
}

addressBookItem.prototype.write = function() {

    var table=document.getElementById("myTable");
    var row=table.insertRow(-1);
    var cell1=row.insertCell(0);
    var cell2=row.insertCell(1);
    var cell3=row.insertCell(2);

    cell1.innerHTML=this.fname;
    cell2.innerHTML=this.lname;
    cell3.innerHTML=this.email;

}

</script>
</head>
<body> 
<script type="text/javascript">
    var aB1 = new addressBookItem('Roger', 'Williams', 'rwilliams@gmail.com');
    var aB2 = new addressBookItem ('Rose', 'Schultz', 'rose_s@earthlink.net');
    aB1.write();
    aB2.write();
</script>
<table id="myTable" border="1">
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Email Address</td>
</tr>
</table>

</body>
</html>
4

0 回答 0