Senin, 19 April 2010

Rakaman Objek

kode html:
<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("43E001", "Dani", "TI", "SI");

    Record[1] = new Mahasiswa("43E001", "Doni", "TI", "SI");

    Record[2] = new Mahasiswa("43E001", "Dina", "TI", "SI");

    Record[3] = new Mahasiswa("43E001", "Dini", "TI", "SI");

    //menampilkan data

    document.write("<table border = '3'>");

    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>");

    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].npm   

        document.write("</tr>");

    }

        document.write("</table>");

//-->

</script>

</body>

</html>  



   

Tidak ada komentar:

Posting Komentar