คุณสมบัติของวัตถุ
การคัดลอกรหัสมีดังนี้:
document.title // ตั้งค่าแท็ก <title> ที่เทียบเท่ากับ html
document.bgcolor // ตั้งค่าสีพื้นหลังหน้า
document.fgcolor // ตั้งค่าสีเบื้องหน้า (สีข้อความ)
document.linkcolor // สีลิงค์ที่ไม่ได้ใช้
document.alinkcolor // เปิดใช้งานสีของลิงค์ (มุ่งเน้นไปที่ลิงค์นี้)
document.vlinkcolor // clicked link color
document.url // ตั้งค่าคุณสมบัติ URL เพื่อเปิดหน้าเว็บอื่นในหน้าต่างเดียวกัน
document.filecreateddate // วันที่สร้างไฟล์, แอตทริบิวต์อ่านอย่างเดียว
document.fileModifiedDate // วันที่แก้ไขไฟล์แอตทริบิวต์อ่านอย่างเดียว
document.filesize // ขนาดไฟล์แอตทริบิวต์อ่านอย่างเดียว
document.cookie // set และอ่านคุกกี้
document.charset // ตั้งค่าตัวละครชุดอักขระภาษาจีนง่าย: GB2312
-
เรื่องเกี่ยวกับร่างกาย
การคัดลอกรหัสมีดังนี้:
document.body // จุดเริ่มต้นและจุดสิ้นสุดของเอกสารเอกสารที่ระบุเทียบเท่ากับ <body> </body>
document.body.bgcolor // ตั้งค่าหรือรับสีพื้นหลังด้านหลังวัตถุ
document.body.link // สีลิงค์ที่ไม่ได้ใช้
document.body.alink // เปิดใช้งานสีของลิงค์ (มุ่งเน้นไปที่ลิงค์นี้)
document.body.vlink // clicked link color
document.body.text // สีข้อความ
document.body.innertext // ตั้งค่าข้อความระหว่าง <body> ... </body>
document.body.innerhtml // ตั้งรหัส HTML ระหว่าง <body> ... </body>
document.body.topmargin // page margin
document.body.leftmargin // page left left margin
document.body.rightmargin // หน้าส่วนขอบขวา
document.body.bottommargin // margin บนหน้า
document.body.background // ภาพพื้นหลัง
document.body.appendchild (otag) // dynamicly สร้างวัตถุ HTML
เหตุการณ์วัตถุทั่วไป
การคัดลอกรหัสมีดังนี้:
document.body.onclick = "func ()" // ตัวชี้เมาส์คลิกที่วัตถุจะถูกทริกเกอร์
document.body.onmouseover = "func ()" // กะพริบเมื่อตัวชี้เมาส์ย้ายไปที่วัตถุ
document.body.onmouseout = "func ()" // กะพริบเมื่อตัวชี้เมาส์ถูกย้ายออกจากวัตถุ
-
ตำแหน่งตำแหน่ง subobject
การคัดลอกรหัสมีดังนี้:
document.location.hash // ส่วนหลังจากหมายเลข #
document.location.host // ชื่อโดเมน + หมายเลขพอร์ต
document.location.hostname // ชื่อโดเมน
document.location.href // url สมบูรณ์
document.location.pathname // ไดเรกทอรี
document.location.port // หมายเลขพอร์ต
document.location.protocol // เครือข่ายโปรโตคอล (http :)
document.location.search // ส่วนหลังจาก? ตัวเลข
เหตุการณ์วัตถุทั่วไป
การคัดลอกรหัสมีดังนี้:
documenty.location.reload () // รีเฟรชหน้าเว็บ
document.location.reload (URL) // เปิดหน้าเว็บใหม่
document.location.assign (URL) // เปิดหน้าเว็บใหม่
document.location.replace (URL) // เปิดหน้าเว็บใหม่
-
คอลเลกชันรูปภาพ (รูปภาพในหน้า)
a) การอ้างอิงผ่านคอลเลกชัน
การคัดลอกรหัสมีดังนี้:
document.images // แท็ก <img> ในหน้าสอดคล้องกัน
document.images.length // จำนวนแท็ก <img> ในหน้าสอดคล้องกัน
document.images [0] // แท็ก <img> ตัวแรก
document.images // i-1 <img> แท็ก
b) การอ้างอิงโดยตรงผ่านแอตทริบิวต์ชื่อ
การคัดลอกรหัสมีดังนี้:
<img name = "oimage">
document.images.oimage //document.images.name คุณสมบัติ
C) แอตทริบิวต์ SRC ของรูปภาพอ้างอิง
การคัดลอกรหัสมีดังนี้:
document.images.oimage.src //document.images.name attribute.src
d) สร้างภาพ
การคัดลอกรหัสมีดังนี้:
var oimage
oimage = ภาพใหม่ ()
document.images.oimage.src = "1.jpg"
ในเวลาเดียวกันสร้างแท็ก <IMG> บนหน้าและสามารถแสดงได้
รหัสตัวอย่าง (การสร้างแบบไดนามิก):
การคัดลอกรหัสมีดังนี้:
<html>
<img name = oimage>
<ภาษาสคริปต์ = "JavaScript">
var oimage
oimage = ภาพใหม่ ()
document.images.oimage.src = "1.jpg"
</script>
</html>
<html>
<ภาษาสคริปต์ = "JavaScript">
oimage = document.caeatelement ("IMG")
oimage.src = "1.jpg"
document.body.appendchild (oimage)
</script>
</html>
-
คอลเลกชันแบบฟอร์ม (แบบฟอร์มในหน้า)
a) การอ้างอิงผ่านคอลเลกชัน
การคัดลอกรหัสมีดังนี้:
document.forms // แท็ก <form> ในหน้าสอดคล้องกัน
document.forms.length // จำนวนแท็ก <form> ในหน้าสอดคล้องกัน
document.forms [0] // แท็ก <Form> ครั้งแรก
document.forms // i-1 <form> แท็ก
document.forms.length // จำนวนการควบคุมใน i-1th <form>
document.forms.elements [j] // การควบคุม J-1st ใน i-1th <form>
-
b) การอ้างอิงโดยตรงผ่านแอตทริบิวต์ชื่อแท็ก
การคัดลอกรหัสมีดังนี้:
<form name = "myform"> <input name = "MyCtrl"> </form>
document.myform.myctrl //document.form name.control ชื่อ
-
C) คุณสมบัติการเข้าถึงแบบฟอร์ม
การคัดลอกรหัสมีดังนี้:
document.forms.name // สอดคล้องกับ <ชื่อฟอร์ม> แอตทริบิวต์
document.forms.action // สอดคล้องกับ <form action> แอตทริบิวต์
document.forms.encoding // สอดคล้องกับแอตทริบิวต์ <form Enctype>
document.forms.target // สอดคล้องกับ <Target Target> แอตทริบิวต์
document.forms.appendchild (otag) // แทรกการควบคุมแบบไดนามิก
-
รหัสตัวอย่าง (แบบฟอร์ม):
การคัดลอกรหัสมีดังนี้:
<html>
<!-สคริปต์ที่เกี่ยวข้องกับการควบคุมข้อความ->
<form name = "myform">
<อินพุต type = "text" name = "otext">
<อินพุต type = "รหัสผ่าน" name = "opswd">
<form>
<ภาษาสคริปต์ = "JavaScript">
// รับค่าของกล่องรหัสผ่านข้อความ
document.write (document.myform.otext.value)
document.write (document.myform.opswd.value)
</script>
</html>
-
โค้ดตัวอย่าง (ช่องทำเครื่องหมาย):
การคัดลอกรหัสมีดังนี้:
<html>
<!-ช่องทำเครื่องหมาย, สคริปต์ที่เกี่ยวข้องกับการควบคุมวิทยุ->
<form name = "myform">
<อินพุต type = "ช่องทำเครื่องหมาย" name = "chk" value = "1"> 1
<อินพุต type = "ช่องทำเครื่องหมาย" name = "chk" value = "2"> 2
</form>
<ภาษาสคริปต์ = "JavaScript">
ฟังก์ชั่นสนุก () {
// โอนค่าควบคุมช่องทำเครื่องหมายและตรวจสอบว่ามีการเลือกหรือไม่
ความยาว var
length = document.forms [0] .chk.length
สำหรับ (i = 0; i <length; i ++) {
v = document.forms [0] .chk.value
b = document.forms [0] .chk.checked
ถ้า (b)
การแจ้งเตือน (v = v+"เลือก")
อื่น
การแจ้งเตือน (v = v+"ไม่ได้เลือก")
-
-
</script>
<a href =# onclick = "fun ()"> ddd </a>
</html>
-
โค้ดตัวอย่าง (เลือก):
การคัดลอกรหัสมีดังนี้:
<html>
<!-เลือกสคริปต์ที่เกี่ยวข้องกับการควบคุม->
<form name = "myform">
<select name = "oselect">
<ตัวเลือกค่า = "1"> 1 </potion>
<ตัวเลือกค่า = "2"> 2 </potion>
<ตัวเลือกค่า = "3"> 3 </potion>
</เลือก>
</form>
<ภาษาสคริปต์ = "JavaScript">
// โอนรายการตัวเลือกของตัวเลือกการเลือก
ความยาว var
length = document.myform.oselect.length
สำหรับ (i = 0; i <length; i ++)
document.write (document.myform.oselect.value)
</script>
<ภาษาสคริปต์ = "JavaScript">
// โอนรายการตัวเลือกและพิจารณาว่ามีตัวเลือกเลือก
สำหรับ (i = 0; i <document.myform.oselect.length; i ++) {
if (document.myform.oselect.Selected! = true)
document.write (document.myform.oselect.value)
อื่น
document.write ("<font color = red>"+document.myform.oselect.value+"</font>")
-
</script>
<ภาษาสคริปต์ = "JavaScript">
// พิมพ์ตัวเลือกที่เลือกตาม SelectedIndex
// (0 ถึง document.myform.oselect.length -1)
i = document.myform.oselect.selectedIndex
document.write (document.myform.oselect.value)
</script>
<ภาษาสคริปต์ = "JavaScript">
// เพิ่มรายการตัวเลือกของตัวเลือกแบบไดนามิกแบบไดนามิก
var ooption = document.createElement ("ตัวเลือก");
ooption.text = "4";
Ooption.value = "4";
document.myform.oselect.add (Ooption);
</script>
<html>
-
Div Collection (เลเยอร์ในหน้า)
การคัดลอกรหัสมีดังนี้:
<div id = "odiv"> ข้อความ </div>
document.all.odiv // layer อ้างอิง odiv
document.all.odiv.style.display = "" // เลเยอร์ถูกตั้งค่าเป็นภาพ
document.all.odiv.style.display = "ไม่มี" // เลเยอร์ถูกตั้งค่าให้ซ่อน
document.getElementId ("odiv") // วัตถุอ้างอิงผ่าน GetElementId
document.getElementId ("ODIV")
document.getElementId ("odiv"). display = "none"
/*document.all แสดงการรวบรวมวัตถุทั้งหมดในเอกสาร
IE เท่านั้นที่รองรับแอตทริบิวต์นี้ดังนั้นจึงใช้เพื่อกำหนดประเภทของเบราว์เซอร์*/
4 คุณสมบัติของวัตถุเลเยอร์
การคัดลอกรหัสมีดังนี้:
document.getElementById ("id"). innerText // ข้อความเอาต์พุตแบบไดนามิก
document.getElementById ("id"). innerhtml // output แบบไดนามิก html
document.getElementById ("id"). outertext // innerText เดียวกัน
document.getElementById ("id"). outerhtml // เหมือนกับ innerhtml
-
รหัสตัวอย่าง:
การคัดลอกรหัสมีดังนี้:
<html>
<ภาษาสคริปต์ = "JavaScript">
ฟังก์ชั่นเปลี่ยน () {
document.all.odiv.style.display = "ไม่มี"
-
</script>
<div id = "odiv" onclick = "เปลี่ยน ()"> ข้อความ </div>
</html>
<html>
<ภาษาสคริปต์ = "JavaScript">
ฟังก์ชั่น ChangetExt () {
document.getElementById ("odiv"). innerText = "newtext"
-
</script>
<div id = "odiv" onMouseOver = "changetExt ()"> ข้อความ </div>
</html>