您的位置:首页 > 移动开发 > IOS开发

ios与js交互

2016-07-22 17:36 405 查看
//1.js往oc传值
var _login = function(mode)
{
document.location=$('uc').value+":"+$('up').value+":"+mode;
}
//js的点击事件传过来的值就是compents数组里面的值
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{

NSString *requestString = [[request URL] absoluteString];
NSArray *compents = [requestString componentsSeparatedByString:@":"];
return YES;
}
//2.oc往js传值
NSString *string = [NSString stringWithFormat:@"$('#title').html('%@');$('#desc').html('%@');$('#money').html('%@')",self.payInfo[@"title"],self.payInfo[@"desc"],self.payInfo[@"money"]];
NSLog(@"string = %@",string);
[webView stringByEvaluatingJavaScriptFromString:string];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios与js 交互