Definisi dan Penggunaan
Untuk elemen tombol, type atribut menentukan jenis tombol.
Untuk elemen input, type atribut menentukan jenis <input> elemen untuk menampilkan.
Untuk elemen menu, yang type atribut menentukan jenis menu.
Untuk embed, Link, objek, naskah, sumber, dan unsur-unsur gaya, dia jenis atribut menentukan jenis media Internet (sebelumnya dikenal sebagai jenis MIME).
Berlaku untuk
The type atribut dapat digunakan pada unsur-unsur berikut:
elemen | Atribut |
---|---|
<button> | type |
<embed> | type |
<input> | type |
<link> | type |
<menu> | type |
<object> | type |
<script> | type |
<source> | type |
<style> | type |
contoh
Button Contoh
Dua elemen tombol yang bertindak sebagai salah satu tombol submit dan satu tombol reset (dalam bentuk):
<form action="demo_form.asp" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit" value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
Cobalah sendiri " Embed Contoh
Tertanam animasi flash dengan jenis media tertentu:
<embed src="helloworld.swf"
type="application/vnd.adobe.flash-movie">
Cobalah sendiri " Input Contoh
Bentuk HTML dengan dua jenis input yang berbeda; teks dan menyerahkan:
<form action="demo_form.asp">
Username: <input type="text" name="usrname"><br>
<input type="submit" value="Submit">
</form>
Cobalah sendiri " Link Contoh
Pada contoh berikut, type atribut menunjukkan bahwa dokumen terkait adalah style sheet eksternal:
<head>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
Cobalah sendiri " Menu Contoh
Sebuah menu konteks:
<menu type="context" id="mymenu">
<menuitem label="Refresh"
onclick="window.location.reload();" icon="ico_reload.png">
</menuitem>
<menu label="Share on...">
<menuitem label="Twitter"
icon="ico_twitter.png"
onclick="window.open('//twitter.com/intent/tweet?text='+window.location.href);">
</menuitem>
<menuitem label="Facebook" icon="ico_facebook.png"
onclick="window.open('//facebook.com/sharer/sharer.php?u='+window.location.href);">
</menuitem>
</menu>
<menuitem label="Email This Page"
onclick="window.location='mailto:?body='+window.location.href;"></menuitem>
</menu>
Cobalah sendiri " Object Contoh
Sebuah <object> elemen dengan jenis media tertentu:
<object width="400" height="400" data="helloworld.swf"
type="application/vnd.adobe.flash-movie"></object>
Cobalah sendiri " Script Contoh
Sebuah script dengan type atribut tertentu:
<script type="text/javascript">
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
Cobalah sendiri " Source Contoh
Gunakan satu type atribut:
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Cobalah sendiri " Style Contoh
Gunakan type atribut untuk menentukan jenis media dari <style> tag:
<style type="text/css">
h1 {color:red;}
p {color:blue;}
</style>
Cobalah sendiri " Dukungan Browser
The type
Atribut memiliki dukungan browser berikut untuk setiap elemen:
Elemen | |||||
---|---|---|---|---|---|
button | iya nih | iya nih | iya nih | iya nih | iya nih |
embed | iya nih | iya nih | iya nih | iya nih | iya nih |
input | iya nih | iya nih | iya nih | iya nih | iya nih |
link | iya nih | iya nih | iya nih | iya nih | iya nih |
menu | Tidak didukung | Tidak didukung | 8,0 (Hanya ketik = "konteks") | Tidak didukung | Tidak didukung |
object | iya nih | iya nih | iya nih | iya nih | iya nih |
script | iya nih | iya nih | iya nih | iya nih | iya nih |
source | 4.0 | 9.0 | 3.5 | 4.0 | 10.5 |
style | iya nih | iya nih | iya nih | iya nih | iya nih |