ตัวอย่างในบทความนี้แบ่งปันรหัสเฉพาะที่เลือกโดยคลิกที่ข้อความของ JS เพื่อค้นหาโดยอัตโนมัติในกล่องแบบเลื่อนลงสำหรับการอ้างอิงของคุณ เนื้อหาเฉพาะมีดังนี้
<html> <head runat = "เซิร์ฟเวอร์"> <title> </title> <style type = "text/css"> #sitestat {width: 97px; ความสูง: 181px; } </style> </head> <body> <จาก> <ภาษาสคริปต์ = JavaScript> function foo () {// var i = 3; var i = document.getElementById ("ds") ค่า; o = document.getElementById ("sitestat"); สำหรับ (c = 0; c <o.length; c ++) {dy = o.options [c] .value.indexof (i) ถ้า (dy == 0) // ถ้า (o.options [c] .value == i) {o.options [c] หยุดพัก; }}}} </script> <select name = "siteStat" multiple = "multiple" id = "sitestat"> <ตัวเลือกค่า = "-1" เลือก> </ตัวเลือก> <ตัวเลือกค่า = "1"> สถานะ A </optup> type = 'text' name = 'olala' id = 'ds'/> <อินพุต type = 'submit' name = 'sub' value = 'Query Display' onclick = "foo ()"/> </body> </html>ข้างต้นเป็นเรื่องเกี่ยวกับบทความนี้และฉันหวังว่ามันจะเป็นประโยชน์สำหรับทุกคนในการเรียนรู้การเขียนโปรแกรม JavaScript