วิธีการ - แสดงข้อความเมื่อเลือกช่องทำเครื่องหมาย
ตรวจสอบว่าช่องทำเครื่องหมายถูกทำเครื่องหมายด้วย JavaScript หรือไม่
แสดงข้อความเมื่อเลือกช่องทำเครื่องหมาย:
ช่องทำเครื่องหมาย:ตรวจสอบว่าได้ทำเครื่องหมายที่ช่องทำเครื่องหมายหรือไม่
ขั้นตอนที่ 1) เพิ่ม HTML:
ตัวอย่าง
Checkbox: <input type="checkbox" id="myCheck" onclick="myFunction()">
<p id="text" style="display:none">Checkbox is CHECKED!</p>
ขั้นตอนที่ 2) เพิ่ม JavaScript:
ตัวอย่าง
function myFunction() {
// Get the checkbox
var checkBox =
document.getElementById("myCheck");
// Get the output text
var text = document.getElementById("text");
// If the checkbox
is checked, display the output text
if (checkBox.checked == true){
text.style.display = "block";
} else {
text.style.display = "none";
}
}