DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JS与OC交互title>
head>
<body>
<div style="margin-top: 20px">
<h2>JS与OC交互
style="color: #2b7ec3">h2>
<
hr /><input type="button" value="唤起app端(iOSMethod)" οnclick="angela.iOSMethod()">
div>
<div>
<input type="button" value="唤起iOSMethodCall方法传值" οnclick="call()">
div>
<div>
<input id="btn" type="button" value="点击我" οnclick="clickMe()"/>
div>
<div >
<input class="myfun" type="button" value="点击" οnclick="clickTest()" />
div>
<script>
document.getElementsByClassName('myfun')[0].style.backgroundColor='aquamarine';
document.getElementsByClassName('myfun')[0].style.borderColor='red';
var call = function()
{
var
callInfo = JSON.stringify({"博客":
"http://blog.sina.com.cn/u/3381251292"});
angela.iOSMethodCall(callInfo);
}
var Callback = function(a,b)
{
alert(a*b);
}
var countNumber=function(a,b,c){
alert(a*b*c);
}
function
arrayParameter(){
var arr=new
Array('angela','lsy','spring');
document.location=arr;
return arr;
}
var clickMe=function(){
;
}
var clickTest=function(){
;
}
script>
body>
html>
//
// ByOCChangeJSAttributeVC.m
// JSAndOCMutual
//
// Created by Angela on 16/9/9.
// Copyright © 2016年 Angela.
All rights reserved.
//
#import
"ByOCChangeJSAttributeVC.h"
@interface
ByOCChangeJSAttributeVC ()<UIWebViewDelegate>
@property(nonatomic,strong)UIWebView
*webView;
@end
@implementation
ByOCChangeJSAttributeVC
- (void)viewDidLoad
{
[super
viewDidLoad];
self.view.backgroundColor=[UIColor
whiteColor];
self.title=@"web2";
_webView=[[UIWebView
alloc]initWithFrame:CGRectMake(0,
0,
self.view.frame.size.width,300)];
_webView.delegate=self;
NSString
*url=[[NSBundle
mainBundle]
pathForResource:@"test"
ofType:@"html"];
[_webView
loadRequest:[NSURLRequest
requestWithURL:[NSURL
URLWithString:url]]];
[self.view
addSubview:_webView];
}
-(void)webViewDidFinishLoad:(UIWebView
*)webView{
// 获取当前页面的title
NSString
*title
= [webView
stringByEvaluatingJavaScriptFromString:@"document.title"];
self.title=title;
// 获取当前页面的url
NSString
*url
= [webView
stringByEvaluatingJavaScriptFromString:@"document.location.href"];
NSLog(@"title=%@\nurl=%@",title,url);
[webView stringByEvaluating[0].style.color='white';"];