我在 jquery 中有这个函数在我的 Target 中保存为 doc2.js,我在我的包资源中有如下副本:
doc2.js:
$(document).ready(function(){
$(".flip").click(function(){
$(".panel").slideToggle("slow");
});
});
在我的 Xcode 中,我有以下内容:
UIWebView * webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"new" ofType:@"html"]isDirectory:NO]]];
webView.delegate=self;
[self.view addSubview:webView];
这个方法:
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *jqueryCDN = @"http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
NSData *jquery = [NSData dataWithContentsOfURL:[NSURL URLWithString:jqueryCDN]];
NSString *jqueryString = [[NSMutableString alloc] initWithData:jquery encoding:NSUTF8StringEncoding];
[webView stringByEvaluatingJavaScriptFromString:jqueryString];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"doc2" ofType:@"js" inDirectory:NO];
NSData *fileData = [NSData dataWithContentsOfFile:filePath];
NSString *jsString = [[NSMutableString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
[webView stringByEvaluatingJavaScriptFromString:jsString];}
在我的 html 文件中:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<style type="text/css">
div.panel,p.flip
{
margin:0px;
padding:5px;
text-align:center;
background:#e5eecc;
border:solid 1px #c3c3c3;
}
div.panel
{
height:120px;
display:none;
}
</style>
</head>
<body>
<div class="panel">
<p>Any Thing.</p>
<p>Any Thing.</p>
</div>
<p class="flip">Show/Hide Panel</p>
</body>
</html>
这段代码应该处理 UIWebView 但它不适用于我我认为我的 jQuery 函数没有完成或类似的任何想法?