<html>
<meta charset='utf-8'/>
<title>javascript</title>
<script>
function a(){
alert('你好');
return 'haha';
}
</script>
<body>
你好啊
<button onclick='alert(1)'>这是一个按钮</button>
</body>
</html>
//
// ViewController.m
// OCCallsJs
//
// Created by hq on 16/4/19.
// Copyright © 2016年 hanqing. All rights reserved.
//
#import "ViewController.h"
@interface ViewController () <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
@implementation ViewController
-(BOOL) prefersStatusBarHidden{
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url=[[NSBundle mainBundle] URLForResource:@"index.html" withExtension:nil];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
self.webView.delegate=self;
}
//加载结束
-(void)webViewDidFinishLoad:(UIWebView *)webView{
[webView stringByEvaluatingJavaScriptFromString:@"a()"];
}
@end