2011-09-14 14 views
4

我第一次使用jQuery-Mobile,我不知道如何在ios中使用我的項目。iOS中的移動jQuery - 如何獲取UIWebView中的元素位置?

我必須導入哪個文件?在http://jquerymobile.com/網站上,我下載了jquery.mobile-1.0b3.js和jquery.mobile-1.0.min.js。我使用哪個?

這是我的代碼。

NSString *path = [[NSBundle mainBundle] pathForResource:@"jquery.mobile-1.0b3" ofType:@"js"]; 
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; 
[self stringByEvaluatingJavaScriptFromString:jsCode]; 

這是正確的?

而我想獲得指定的元素。在jQuery中,有一個函數 - '.position' 但手機jquery支持這個功能嗎?我怎麼能夠?

NSString *code = @"var p=$('p:first'); var pos=p.position();" 
NSLog(@"%@", [webView stringByEvaluatingJavaScriptFromString:@"position.left"]); 

請幫幫我。

在此先感謝。

回答

1

我承認,我不知道如何使用PhoneGap的或UIWebView的還,但...這是你如何使用jQuery和jQuery Mobile的獲得位置,如果它是一個普通的網頁。

我可以誤解你,但你似乎是的印象是jQuery Mobile的JS或者是用於替代或包括基本水平jQuery庫下。不是這種情況。爲了使jQuery的移動工作你需要首先基礎級jQuery庫。任何jQuery Mobile的頁面的頭部包括以下...

jquery.mobile-1.0rc2.min.css 
jquery-1.6.4.min.js 
jquery.mobile-1.0rc2.min.js 

一旦你在頁面這些資產,你可以找到一個這樣的元素的位置...

var position = $("#idOfElementOrSomeOtherSelector").position(); 
alert("the element is at top: "+position.top+" left: "+position.left); 

我我不確定這是如何隨着PhoneGap的變化,但運氣好,這應該給你一個線索。