จากที่ทดลองทำนะคะ คือว่าพอสร้างฟังก์ชั่นไว้หน้า js แล้วเรียกใช้งานไม่ได้ค่ะ ไม่รู้ว่าการทำให้หน้า js รู้จักกับ html ถูกไหม ใช้โค้ดนี้ในส่วน head ของ html แต่ไม่ได้
โค้ด: เลือกทั้งหมด
<script type="text/javascript" src="index.js"></script>
เลยทดสอบเขียนฟังก์ชันในหน้า html เลย สามารถเปลี่ยนหน้าไปมาได้
โค้ดหน้า index.html
โค้ด: เลือกทั้งหมด
<html>
<head>
<script>
function sh_index() {
window.location = 'page2.html';
}
setTimeout('sh_index()',10000);
</script>
</head>
<body>
<a href="#" onclick="sh_index()">Click me to Page2</a>
</body>
</html>
โค้ดหน้า page2.html
โค้ด: เลือกทั้งหมด
<html>
<head>
<script>
function sh_page2() {
window.location = 'index.html';
}
setTimeout('sh_page2()',10000);
</script>
</head>
<body>
<a href="#" onclick="sh_page2()"> Click me to Index </a>
</body>
</html>
ผลลัพธ์คือ สามารถเชื่อมหน้ากลับไปกลับมาได้ เลยอยากทราบว่าอยากให้เปลี่ยนเป็นการเขียนฟังก์ชันไว้หน้า js และเรียกใช้งานหน้า html ตรงส่วนนี้ทำยังไงหรอคะ