ด้วยสํานึกในพระมหากรุณาธิคุณสมเด็จพระนางเจ้าสิริกิติ์เป็นล้นพ้นอันหาที่สุดมิได้
ด้วยสํานึกในพระมหากรุณาธิคุณสมเด็จพระนางเจ้าสิริกิติ์เป็นล้นพ้นอันหาที่สุดมิได้


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

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

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

ปัจจุบัน นักพัฒนาสามารถ ใช้ ChatGPT | Gemini | Claude | Perplexity | Deepseek ช่วยในการแก้ไขปัญหาต่างๆ ในการเขียนโปรแกรม หรือหาข้อมูลเพิ่มเติมได้ง่ายและสะดวก แนะนำให้ทุกคนใช้งานเพื่อพัฒนาศักยภาพของตัวเอง

ดูแล้ว 7,743 ครั้ง


 ชะลอการทำงานของ  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







Tags:: jquery holdready







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








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