รู้จัก holdReady ของ jQuery เวอร์ชั่น 1.6 เป็นต้นไป

เขียนเมื่อ 11 ปีก่อน โดย Ninenik Narkdee
jquery holdready

คำสั่ง การ กำหนด รูปแบบ ตัวอย่าง เทคนิค ลูกเล่น การประยุกต์ การใช้งาน เกี่ยวกับ jquery holdready

ดูแล้ว 6,821 ครั้ง


 ชะลอการทำงานของ  jQuery s ready event. และให้ทำงานในส่วนของ script 

ที่กำหนดก่อน แล้วค่อยทำงานในส่วนของ jQuery s ready event.
 
ทดสอบรันไฟล์ ข้างต้น เพื่อเปรียบเทียบลำดับการทำงาน
 
ไฟล์ jq_learn121112_1.php case 1
 
<!DOCTYPE html>
<html>
<head>
<style>div { color:red; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>


<script type="text/javascript">
console.log("1");
$.holdReady(true);
$.getScript("myplugin.js", function() {
	console.log("2");
     $.holdReady(false);
	 console.log("3");
});
</script>
<script type="text/javascript">
console.log("4");
$(function(){
	console.log("5");
});
console.log("6");
</script>




</body>
</html>
<script type="text/javascript">
console.log("7");
</script>
 
 
ไฟล์ jq_learn121112_1.php case 2
 
<!DOCTYPE html>
<html>
<head>
<style>div { color:red; }</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>


<script type="text/javascript">
console.log("1");
//$.holdReady(true);
$.getScript("myplugin.js", function() {
	console.log("2");
//     $.holdReady(false);
	 console.log("3");
});
</script>
<script type="text/javascript">
console.log("4");
$(function(){
	console.log("5");
});
console.log("6");
</script>




</body>
</html>
<script type="text/javascript">
console.log("7");
</script>
 
 
ไฟล์ myplugin.js สำหรับทดสอบ
 
// JavaScript Document
console.log("test sample plugin");
 
 
ดูผลลัพธ์หลังจากรันโค้ดใน แท็บ console ใน google chrome โดยกด F12
สังเกตลำดับการรันของตัวเลขที่แสดง รวมทั้งผลลัพธ์การทำงานของ ไฟล์ myplugin.js


กด Like หรือ Share เป็นกำลังใจ ให้มีบทความใหม่ๆ เรื่อยๆ น่ะครับ





Tags:: jquery holdready







URL สำหรับอ้างอิง





คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )







เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ