Input Radio dicentang Properti
Contoh
Centang dan hapus centang pada tombol radio tertentu:
function check() {
document.getElementById("red").checked = true;
}
function uncheck() {
document.getElementById("red").checked = false;
}
Definisi dan Penggunaan
Properti yang dicentang mengatur atau mengembalikan status tombol radio yang dicentang.
Properti ini mencerminkan atribut HTML yang dicentang.
Dukungan Peramban
Property | |||||
---|---|---|---|---|---|
checked | Yes | Yes | Yes | Yes | Yes |
Sintaksis
Kembalikan properti yang dicentang:
radioObject.checked
Setel properti yang dicentang:
radioObject.checked = true|false
Nilai properti
Value | Description |
---|---|
true|false |
Specifies whether a radio button should be checked or not.
|
Detail Teknis
Nilai Kembali: | Sebuah Boolean, mengembalikan true jika tombol radio dicentang, dan false jika tombol radio tidak dicentang |
---|
Lebih Banyak Contoh
Contoh
Cari tahu apakah tombol radio dicentang atau tidak:
var x = document.getElementById("myRadio").checked;
Contoh
Gunakan tombol radio untuk mengonversi teks di bidang input menjadi huruf besar:
document.getElementById("fname").value = document.getElementById("fname").value.toUpperCase();
Contoh
Beberapa tombol radio dalam bentuk:
var coffee = document.forms[0];
var txt = "";
var i;
for (i = 0; i < coffee.length; i++) {
if (coffee[i].checked) {
txt = txt + coffee[i].value + " ";
}
}
document.getElementById("order").value = "You ordered a coffee with: " + txt;
Halaman Terkait
Referensi HTML: HTML <input> atribut yang dicentang
Masukan Objek Radio