CSMJU jQuery Mobile

เมนู
ถัดไป ก่อนหน้า

4.1 Configuring defaults

การกำหนดค่าเริ่มต้น (Configuring defaults)

   jQuery Mobile แตกต่างจาก jQuery และ jQuery UI โดย jQuery Mobile จะนำมาร์กอัปที่มี การปรับปรุงมาประยุกต์ใช้อย่างอัตโนมัติ โดยจะนำมาใช้ในการตั้งค่าเริ่มต้นพื้นฐานของ jQuery Mobile ซึ่งถูกออกแบบมาเพื่อทำงานร่วมกับ common scenarios ทำให้ง่ายต่อการกำหนดค่า เมื่อเริ่มใช้ jQuery Mobile จะเรียก mobileinit event ขึ้นมาแทนที่ค่าเริ่มต้น โดยผูกติดกับ mobileinit


$(document).bind("mobileinit", function(){
  //apply overrides here 
});

   เพราะ mobileinit event จะถูกเรียกทันที ฉะนั้นต้องผูก event handler ก่อนที่จะมีการโหลด jQuery Mobile ตามคำสั่งที่เชื่อมโยงไปยังไฟล์ JavaScript


<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>

   สามารถแทนที่การตั้งค่าเริ่มต้นโดยการextend objectที่ชื่อว่า $.mobile ซึ่งจะอยู่ใน method $.extend ของ jQuery


$(document).bind("mobileinit", function(){
  $.extend(  $.mobile , {
    foo: bar});
});

   หรือ ตั้งค่าได้โดยใช้ object property notation (คุณสมบัติของวัตถุ)


$(document).bind("mobileinit", function(){
  $.mobile.foo = bar;
});

การกำหนดตัวเลือก (Configurable options)

   ค่าเริ่มต้นต่อไปนี้จะกำหนดผ่าน object ที่ชื่อว่า $.mobile