Minggu, April 12, 2009

Rekaman Objek

Rekaman Objek

?html>
?head>?title>Membuat Rekaman Objek?/title>?/head>
?body>
?script language = "javascript">
?!--
var Record = new Array();
function Mahasiswa (npm, nama, prodi, jenjang)
{//properti
this.npm = npm;
this.nama = nama;
this.prodi = prodi;
this.jenjang = jenjang;

//Metode
this.LihatRecordMahasiswa = LihatRecordMahasiswa;
}
function LihatRecordMahasiswa()
{
document.write("?td>" +this.npm+ "?/td>");
document.write("?td>" +this.nama+ "?/td>");
document.write("?td>" +this.prodi+ "?/td>");
document.write("?td>" +this.jenjang+ "?/td>");
}
//Mengisi data
Record[0]=new Mahasiswa("0001","Dani","TI","SI");
Record[1]=new Mahasiswa("0002","Doni","TK","D3");
Record[2]=new Mahasiswa("0003","Dina","SI","SI");
Record[3]=new Mahasiswa("0004","Dini","KA","D3");
//Menampilkan Data
document.write("?table border='1'>");
document.write("?th>npm?/th>?th>nama?/th>");
document.write("?th>prodi?/th>?th>jenjang?/th>?br>");
for (i=0; i ? Record.length; i++)
{
document.write("?tr>");
Record[i].LihatRecordMahasiswa();
document.write("?/tr>");
}
document.write("?/table>?br>");
//-->
?/script>
?/body>
?/html>


hasilnya sebagai berikut

Tidak ada komentar: