2011-09-13 40 views
0

第一次使用jQuery手機,並在第一次嘗試處理pagecreate事件時出現錯誤。pagecreate事件導致javascript錯誤 - 我做錯了什麼?

$('body').live('pagecreate',function(event){ 
    alert('hello world'); 
}); 

顯示在Chrome這個錯誤(在iPad上類似的錯誤):

Uncaught TypeError: Object function (a,b){return new c.fn.init(a,b)} has no method  'type' 
i.parseUrljquery.mobile-1.0b3.min.js:45 
bjquery.mobile-1.0b3.min.js:51 
(anonymous function) 

同樣的錯誤,如果我嘗試使用任何其他選擇,比如我的#container DIV發生。我確信我在這裏做了一些相當基本的錯誤,任何建議表示讚賞!

乾杯, 馬克。

+0

這裏的錯誤發生的一個例子: HTTP:// WWW .markdavies.com.au/staging/test/jqmobile/ – koosa

+0

看起來好像我的問題是最小的jQuery版本。更改該行以使用jquery 1.6.1,問題已解決。 – koosa

+0

此頁面幫助了我很多:http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/pages/docs-pages.html – koosa

回答

0

你的問題是你綁定到body標籤並需要綁定到一個頁面id。更多的文檔:

你有

$('body').live('pagecreate',function(event){ 
    alert('hello world'); 
}); 

應該

$('#pageId').live('pagecreate',function(event){ 
    alert('hello world'); 
});