Skip to content

Commit b325279

Browse files
committed
iOS
1 parent bc39e9b commit b325279

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

JS2iOS/JS2iOS.xcodeproj/project.pbxproj

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@
304304
A65943791C896EB100ACCECA /* Release */,
305305
);
306306
defaultConfigurationIsVisible = 0;
307+
defaultConfigurationName = Release;
307308
};
308309
/* End XCConfigurationList section */
309310
};

JS2iOS/JS2iOS/Info.plist

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
<string>1</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
25+
<key>NSAppTransportSecurity</key>
26+
<dict>
27+
<key>NSAllowsArbitraryLoads</key>
28+
<true/>
29+
</dict>
2530
<key>UILaunchStoryboardName</key>
2631
<string>LaunchScreen</string>
2732
<key>UIMainStoryboardFile</key>

JS2iOS/JS2iOS/ViewController.m

+16-12
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ - (void)viewDidLoad {
4444
class_addProtocol([ViewController class],@protocol(JSTungExport));
4545

4646
// Do any additional setup after loading the view.
47-
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"js_1.html"];
48-
47+
//NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"js_1.html"];
48+
49+
NSString *path = @"http://192.168.5.180:8080/trs/jsoc.html";
50+
4951
myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-20)];
5052
myWebView.delegate = self;
5153
NSURL *URL = [NSURL URLWithString:path];
@@ -88,17 +90,18 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView{
8890
};
8991
}
9092

91-
- (void)updateWeb{
93+
- (void)updateWeb:(NSString*)name{
9294
//网页元素增删改
93-
[context evaluateScript:
94-
@"var para=document.createElement('p');"
95-
"var node=document.createTextNode('This is new.');"
96-
"para.appendChild(node);"
97-
98-
"var element=document.getElementById('d1');"
99-
"element.appendChild(para);"
100-
];
101-
[myWebView reload];
95+
NSString *js = [NSString stringWithFormat:
96+
@"var para=document.createElement('p');"
97+
"var node=document.createTextNode('欢迎'+'%@' + '登入');"
98+
"para.appendChild(node);"
99+
100+
"var element=document.getElementById('d1');"
101+
"element.appendChild(para);"
102+
,name];
103+
104+
[context evaluateScript:js];
102105
}
103106

104107
-(void)testArray:(NSArray *)dataArray{
@@ -110,6 +113,7 @@ -(NSString*)responeToWeb{
110113
}
111114

112115
-(BOOL)login:(NSString*)name password:(NSString*)pwd{
116+
[self updateWeb:name];
113117
return true;
114118
}
115119

JS2iOS/JS2iOS/js_1.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
log("登陆:" + flag);
2828
}
2929

30+
function update(){
31+
var para=document.createElement('p');
32+
var node=document.createTextNode('This is new.');
33+
para.appendChild(node);
34+
35+
var element=document.getElementById('d1');
36+
element.appendChild(para);
37+
}
38+
3039
</script>
3140

3241
</head>
@@ -51,15 +60,15 @@
5160
<br/>
5261

5362
<div id="d1">
54-
<p id="p1">This is a paragraph.</p>
63+
<p id="p1">HTML 元素增删改.</p>
5564
</div>
5665

5766
<form id="login">
5867
<h1>登录</h1>
5968

6069
<input id="username" type="text" placeholder="用户名" autofocus required>
6170
<input id="password" type="password" placeholder="密码" required>
62-
<input type="submit" id="submit" value="登录" onclick="login();">
71+
<input type="button" id="submit" value="登录" onclick="login();">
6372

6473
</form>
6574

0 commit comments

Comments
 (0)