Monday, February 25, 2013

Object String



1.      Menghitung Karakter
-length
2.      Menguji Stirng
- indexOf (“string”)
- match(“string”)

3.      Memunjulkan bagian string tertentu
- Substr(start_num,value)
- Substring(start_num,value_from_begin)

4.      Mengganti karakter
-replace (“string”,”change with”)

5.      Mengubah huruf besar/kecil
-toLowerCase()
-toUpperCase()
6.      Style string
-big()
-small()
-bold()
-italics()
-fixed()
-strike()
-fontcolor(“color_name”)
-fontsize(“#value”)
-sub
-sup

example :
<script language="javascript">
<!--
    document.write("<font face ='trebuchet ms' color='#88c4ff'>");
    str="STMIK Pontianak"
    document.write ("Karakter = ",str,"<br>")
    document.write ("Panjang Karakter = ",str.length,"<br>")
    document.write ("Uji Karakter STMIK = ",str.indexOf("STMIK"),"<br>")
    document.write ("Uji Karakter STMIK = ",str.match("STMIK"),"<br>")
    document.write ("Uji Karakter MTK = ",str.indexOf("MTK"),"<br>")
    document.write ("Uji Karakter MTK = ",str.match("MTK"),"<br>")
    document.write ("Karakter ke 5,8 = ",str.substr("5,8"),"<br>")
    document.write ("Karakter ke 5,8 = ",str.substring("5,8"),"<br>")
    document.write ("Ganti Karakter  = ",str.replace("Pontianak","Jakarta"),"<br>")
    document.write ("Upper Case= ",str.toUpperCase(),"<br>")
    document.write ("Lower Case= ",str.toLowerCase(),"<br>")
    document.write ("Style Big= ",str.big(),"<br>")
    document.write ("Style Small= ",str.small(),"<br>")
    document.write ("Style Bold= ",str.bold(),"<br>")
    document.write ("Style Italics= ",str.italics(),"<br>")
    document.write ("Style Fixed= ",str.fixed(),"<br>")
    document.write ("Style Strike= ",str.strike(),"<br>")
    document.write ("Style Font Color= ",str.fontcolor("pink"),"<br>")
    document.write ("Style Font Size= ",str.fontsize("#5"),"<br>")
    document.write ("Style Sub= ",str.sub(),"<br>")
    document.write ("Style Sup= ",str.sup(),"<br>")
    document.write("</font>");

//-->
</script>


getElementByID
  <html>
<head>
<title>Untitled Document</title>
<script language="javascript">
function cetak()
{
    document.getElementById("hasil").innerHTML = "Bleajar Java script";
}
</script>
</head>

<body>
    <input type="button" value="cetak" onclick="cetak()" />
    <p id="hasil"> </p>
</body>
</html>


Contoh pada input tanpa adanya form pada inputnya
<script language="javascript">
function lala()
{
    if (document.getElementById("hobby").checked)
    {
        document.getElementById("cetak").innerHTML="lalala"
    }
    else
    {
        document.getElementById("cetak").innerHTML="lasdfsfg"
    }
}
</script>
</head>

<body>
<input type="checkbox" id="hobby"  onclick="lala()">lalala
<p id="cetak"> </p>
</body>


Untu


No comments:

Post a Comment

Kebahagiaan sejati bukanlah pada saat kita berhasil meraih apa yg kita perjuangkan, melainkan bagaimana kesuksesan kita itu memberi arti atau membahagiakan orang lain.