คำถาม:
หากฉันลิงก์ในไฟล์ JavaScript สองไฟล์ทั้งที่มี$(document).ready
ฟังก์ชั่นจะเกิดอะไรขึ้น หนึ่งเขียนทับอีกหรือไม่ หรือทั้งสอง$(document).ready
ได้รับการเรียก?
ตัวอย่างเช่น,
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="http://.../jquery1.js"></script>
<script type="text/javascript" src="http://.../jquery2.js"></script>
jquery1.js:
$(document).ready(function(){
$("#page-title").html("Document-ready was called!");
});
jquery2.js:
$(document).ready(function(){
$("#page-subtitle").html("Document-ready was called!");
});
ฉันแน่ใจว่าเป็นวิธีปฏิบัติที่ดีที่สุดในการรวมการโทรทั้งสองเข้าไว้ด้วยกัน$(document).ready
ในสถานการณ์ของฉัน