คัดลอกรหัสรหัสดังต่อไปนี้:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<หัว>
<title>การจัดการเหตุการณ์อย่างง่าย</title>
<meta http-equiv="คำหลัก" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="นี่คือหน้าของฉัน">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
-
<script language="text/javascript" src="hello.html">แท็กการโทรภายนอกของ js นี้ไม่สามารถลงท้ายด้วยตัวมันเองได้</script>
<link rel="stylesheet" type="text/css" href="./styles.css">
-
<script type="text/javascript">
ฟังก์ชั่นคลิกD (obj) {
การแจ้งเตือน (obj.innerHTML);
-
ฟังก์ชั่น mouseD (obj) {
obj.style.color = "#f00";
//เมื่อใช้โค้ดเพื่อกำหนดสไตล์ ถ้า CSS แทนด้วย - จะต้องทำเครื่องหมายด้วย Camel Case Font-size -> FontSize
obj.style.fontSize = "16px";
-
ฟังก์ชั่น outD (obj) {
obj.style.color = "#000";
obj.style.fontSize = "18px";
-
// การใช้ with
ด้วย(เอกสาร){
write("dddd<br/>");
-
document.write("aaaa<br/>");
document.write("bbbb<br/>");
document.write("cccc<br/>");
</สคริปต์>
</หัว>
<ร่างกาย>
<div onclick="clickD(this)" style="cursor:pointer;">คลิกแล้วลองดู</div>
<div onmouseover="mouseD(this)" onmouseout="outD(this)">ลองเลื่อนเมาส์</div>
</ร่างกาย>
</html>
2. ตัวอย่างของวัตถุเบราว์เซอร์: "เกี่ยวข้องกับการถ่ายโอนค่าระหว่างสองหน้าเบราว์เซอร์"
คัดลอกรหัสรหัสดังต่อไปนี้:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="th">
<หัว>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js01_hello</title>
<meta name="author" content="ผู้ดูแลระบบ" />
<script type="text/javascript">
// setTimeout("endWelcome()",5000);
// ฟังก์ชั่น endWelcome() {
// document.getElementById("ยินดีต้อนรับ").style.display = "none";
-
</สคริปต์>
</หัว>
<ร่างกาย>
<div id="welcome">ยินดีต้อนรับสู่เว็บไซต์ของเรา</div>
<a href="#" onclick="window.open('test02.html','aaa','width=300,height=300,resizable=0')">test02</a>
<a href="#" onclick="window.open('test03.html','aaa','width=400,height=400,resizable=0')">test03</a>
<br/>
<a href="#" onclick="window.open('bless.html','aaa','width=600,height=300')">ป้อนคำอวยพรของคุณ</a>
<a href="#" onclick="window.open('bless.html','aaa','width=600,height=300')">เลือกเพศ</a>
<div id="อวยพร"></div>
</ร่างกาย>
</html>
คัดลอกรหัสรหัสดังต่อไปนี้:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="th">
<หัว>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js01_hello</title>
<meta name="author" content="ผู้ดูแลระบบ" />
<script type="text/javascript">
ฟังก์ชั่นอวยพร () {
//รับคำอวยพรอินพุต
var mb = document.getElementById("mb").value;
//รับหน้าต่างหลัก
var p = window.opener;
//รับ div พร้อม ID bless ในหน้าต่างหลัก
var pd = p.document.getElementById("อวยพร");
//ตั้งค่าเป็น pd
pd.innerHTML = MB;
//ปิดหน้าต่างปัจจุบัน
หน้าต่าง.ปิด();
-
</สคริปต์>
</หัว>
<ร่างกาย>
ป้อนคำอวยพร:<input type="text" size="40" id="mb"/><input type="button" onclick="bless()" value="input" />
</ร่างกาย>
</html>