使用jQTouch幾個常見問題的解決辦法
最近在開發(fā)iPhone版的網(wǎng)站,接觸到了一個jQuery插件,叫jQTouch。 這個插件是專門針對iPhone做jQuery效果的。但是在使用中遇到了許多問題,大部分是和之前的Javascript寫法的沖突,列在下面以供參考。
1、頁面跳轉(zhuǎn) jQTouch需要用target="_webapp"來做頁面跳轉(zhuǎn),不然會出問題噢。
2、tap和click 網(wǎng)上搜到有人在問: I noticed an interesting bug with the JQTouch platform and wanted to know if anyone else has run into it our has a workaround for it. If I have a link with an onclick event and lightly tap the link on the iPhone, the link works, but the click event is not fired. If I tap the same link harder, the event fires. Any thoughts on this? 解決方法是使用tap來代替click。iOS系列會在輕觸鏈接時產(chǎn)生tap事件,重觸產(chǎn)生tap和click事件。 當然你可以使用這樣的語句來判斷系統(tǒng)
var userAgent = navigator.userAgent.toLowerCase(); var isiPhone = (userAgent.indexOf('iphone') != -1) ? true : false; if(userAgent.indexOf('ipod') != -1) isiPhone = false; // turn off taps for iPod Touches clickEvent = isiPhone ? 'tap' : 'click'; $('#somelink').bind(clickEvent, function(){...});
3、與Ajax的不兼容 jQTouch將頂層的多個div分成多個頁面顯示,是靠div的id來進行跳轉(zhuǎn)的。 如果你用Ajax來把整個div刷新,那么在back的時候就找不到原來的div id了,一方面使用back會出錯,另一方面在跳轉(zhuǎn)div的時候Ajax新拿到的頁面不會被去掉class="current"標記,導(dǎo)致幾個頁面重疊顯示。如果跳到的頁面比較長那還好,否則就杯具了…… 暫時遇到這幾個,有遇到再補充!
來源:http://kylinhuang.blog.163.com/blog/static/18259419620101166344177/