2012-04-25 49 views
1

我已經創建了一個jquery移動的例子,它在jsfiddle.net中完全正常工作,但在任何瀏覽器中都不起作用。我提供相關鏈接,您可以在瀏覽器和jsfiddle中進行測試。Jquery移動示例不能在瀏覽器中工作

note:jsfiddle.net is the site where you can run and test the jquery examples. 

    for brower : http://errortec.blogspot.in/  

    u can copy the code from the errortec.blogspot.in and place it in your html file and check it in ur browser so that u can understand the problem 

回答

0
In this case try to keep the javascript in on windows.load() as shown below : 

    <script type="text/javascript"> 
     window.onload=function(){ 

      $('#prevchild').click(function() { 

        $.mobile.changePage($('#home'), { 
        transition: 'slide', 
        reverse: true 
       }); 
      }); 

      $('#nextchild').click(function() { 

       $.mobile.changePage($('#child'), { 
        transition: 'slide', 
        reverse: true 
       }); 
      }); 

      $('#login').click(function() { 
       $.mobile.changePage($('#child'), { 
        transition: 'slide', 
        reverse: true 
       }); 
      }); 

      $('#back').click(function() { 
       $.mobile.changePage($('#home'), { 
        transition: 'slide', 
        reverse: true 
       }); 
      }); 

      $('#next').click(function() { 
       $.mobile.changePage($('#child'), { 
        transition: 'slide', 
        reverse: true 
       }); 
      }); 

      $('#prev').click(function() { 
       $.mobile.changePage($('#home'), { 
        transition: 'slide', 
        reverse: true 
       }); 
      }); 
} 

腳本是通過使用的onload執行&後的主體部件被加載()腳本的組分之後將執行加載它,以便組件將知道該腳本 我嘗試了並且是有益的,以我的;我希望有一個面臨同樣問題的人會發現它有幫助。

0

你的身體沒有開始標籤。它應該在最後一個腳本標記和第一個div之間開始。

+0

哎呀索裏,但我糾正我的代碼仍然有同樣的問題 – unkown 2012-04-25 05:15:56

2

嘗試在待機功能封裝腳本:

$(document).ready(function() { 
//your script here 
}); 

還有一個拼寫錯誤腳本標籤的文本屬性爲文本/ javacsript。 如果您僅爲鏈接使用href屬性,導航功能也應該有效。 對於jQuery的移動,一些特定的事件可用:pageinit,pagecreate,pageshow。

更新:你的點擊處理程序應該在jQuery的準備處理程序被添加:

<script type="text/javascript"> 
$(document).ready(function() { 
    $('#prevchild').click(function() { 
     $.mobile.changePage($('#home'), { 
      transition: 'slide', 
      reverse: true 
     }); 
    }); 

    $('#nextchild').click(function() { 
     $.mobile.changePage($('#child'), { 
      transition: 'slide', 
      reverse: true 
     }); 
    }); 
    $('#login').click(function() { 
     $.mobile.changePage($('#child'), { 
      transition: 'slide', 
      reverse: true 
     }); 
    }); 
    $('#back').click(function() { 
     $.mobile.changePage($('#home'), { 
      transition: 'slide', 
      reverse: true 
     }); 
    }); 

    $('#next').click(function() { 
     $.mobile.changePage($('#child'), { 
      transition: 'slide', 
      reverse: true 
     }); 
    }); 

    $('#prev').click(function() { 
     $.mobile.changePage($('#home'), { 
      transition: 'slide', 
      reverse: true 
     }); 
    }); 
}); 
</script> 

我曾嘗試在Chrome的代碼,並將其與該小的變化工作。

+0

我不明白UR答案高於0票下來接受 \t 嘗試在待機功能封裝腳本: $(文件)。就緒(函數( ){ //你的腳本在這裏 }); ,我會檢查拼寫錯誤 – unkown 2012-04-25 06:17:24

+0

邏輯上你的答案是正確的,但在這種情況下,它不工作 – unkown 2012-04-26 10:16:08

相關問題