JS รับจำนวนองค์ประกอบของกล่องรายการแบบเลื่อนลง
การคัดลอกรหัสมีดังนี้:
<! doctype html>
<html>
<head>
<script>
ฟังก์ชั่น getLength ()
-
Alert (document.getElementById ("myselect"). ความยาว); // จำนวนองค์ประกอบ
-
</script>
</head>
<body>
<form>
<เลือก id = "myselect">
<petion> Apple </petion>
<potion> ลูกแพร์ </petion>
<porture> กล้วย </petion>
<pontion> สีส้ม </potion>
</เลือก>
<อินพุต type = "ปุ่ม" onclick = "getLength ()" value = "มีกี่ตัวเลือกในรายการ?">
</form>
</body>
</html>