html文件的代码

 <!DOCTYPE html>
<html>
<head>
<title>标题</title>
</head> <body>
<input type="button" class="inputBut" name="test" value="send massage"
onClick="myFunction()">
</body> <script type="text/javascript">
function myFunction()
{
alert("Hello World!");
}
</script>
</html>

iOS 工程的代码

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
 #import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; self.window.rootViewController = [[RootViewController alloc] init]; [self.window makeKeyAndVisible];
return YES;
} @end
#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end
 #import "RootViewController.h"

 @interface RootViewController ()

 @property (nonatomic, strong)UIWebView *webView;

 @end

 @implementation RootViewController

 - (void)viewDidLoad {
[super viewDidLoad];
self.webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.view addSubview:self.webView];
// self.webView.hidden = YES; // 加载本地HTML文件
NSString *path = [[NSBundle mainBundle] pathForResource:@"button" ofType:@"html"];
NSURL *url = [NSURL URLWithString:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request]; // 添加按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(, , , );
btn.backgroundColor = [UIColor redColor];
[btn setTitle:@"触发js按钮" forState:];
[btn addTarget:self action:@selector(callJavaScriptFunction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; } - (void)callJavaScriptFunction:(UIButton *)sender
{
NSString *aString = [self.webView stringByEvaluatingJavaScriptFromString:@"myFunction();"];
NSLog(@"=== %@",aString);
} @end

通过iOS中的按钮来触发html文件中按钮所触发的函数的更多相关文章

  1. Asp.net中存储过程拖拽至dbml文件中,提示无法获得返回值

    Asp.net中存储过程拖拽至dbml文件中,提示无法获得返回值,去属性表中设置这时候会提示你去属性表中更改返回类型. 其实存储过程返回的也是一张表,只不过有时候存储过程有点复杂或者写法不规范的话不能 ...

  2. Android中通过代码获取arrays.xml文件中的数据

    android工程res/valuse文件夹下的arrays.xml文件中用于放各种数组数据,比如字符串数组.整型数组等,数组中的数据可能是具体的值,也有可能是对资源数据的引用,下面针对这两种情况通过 ...

  3. 在Android中把内容写到XML文件中

    在Android中把内容写到XML文件中 saveXmlButton.setOnClickListener(new OnClickListener() { @Override public void ...

  4. 将一个文件中的内容,在另一个文件中生成. for line in f1, \n f2.write(line)

    将一个文件中的内容,在另一个文件中生成. 核心语句: for line in f1: f1中的所有一行 f2.write(line)                                  ...

  5. java算法面试题:编写一个程序,将a.txt文件中的单词与b.txt文件中的单词交替合并到c.txt文件中,a.txt文件中的单词用回车符分隔,b.txt文件中用回车或空格进行分隔。

    package com.swift; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File ...

  6. 利用POI抽取word中的图片并保存在文件中

    利用POI抽取word中的图片并保存在文件中 poi.apache.org/hwpf/quick-guide.html 1.抽取word doc中的图片 package parse; import j ...

  7. ios 将Log日志重定向输出到文件中保存

    对于真机,日志没法保存,不好分析问题.所以有必要将日志保存到应用的Docunment目录下,并设置成共享文件,这样才能取出分析. 首先是日志输出,分为c的printf和标准的NSLog输出,print ...

  8. Excel表格中依据某一列的值,将这列中一样的数据放在一个文件中。

    一需求:按照标题C的内容,一样的数据整理到一个文件中. 二.操作: 1.atl+F11弹出vb窗口 2.点击       插入===>模块   ,复制以下代码,注意这是一个表头为三行的函数(保存 ...

  9. 直接把数据库中的数据保存在CSV文件中

    今天突然去聊就来写一个小小的demo喽,嘿嘿 public partial class Form1 : Form { public Form1() { InitializeComponent(); } ...

  10. SQL C# nvarchar类型转换为int类型 多表查询的问题,查询结果到新表,TXT数据读取到控件和数据库,生成在控件中的数据如何存到TXT文件中

    在数据库时候我设计了学生的分数为nvarchar(50),是为了在从TXT文件中读取数据插入到数据库表时候方便,但是在后期由于涉及到统计问题,比如求平均值等,需要int类型才可以,方法是:Conver ...

随机推荐

  1. @angular/cli项目构建--interceptor

    JWTInterceptor import {Injectable} from '@angular/core'; import {HttpEvent, HttpHandler, HttpInterce ...

  2. Java VM(虚拟机) 参数

    -XX:PermSize/-XX:MaxPermSize,永久代内存: 1. 虚拟机参数:-ea,支持 assert 断言关键字 eclipse 默认是不开启此参数的,也就是虽然编译器支持 asser ...

  3. 使用range()生成自然数序列

  4. HDU3577Fast Arrangement(线段树+lazy)

    Problem Description Chinese always have the railway tickets problem because of its' huge amount of p ...

  5. centos 下配置oracle11gR2开机自启

    这里使用的环境是 CentOS 6.6 ,并且已经装好了oracle11gR2 oracle启动分为两个步骤: 1.启动监听 2.启动服务 1.root 用户下修改ORATAB(将N该为Y): [ro ...

  6. ORACLE删除用户的有的表的方法

    首先我们查询oracle用户下的所有表 select * from all_tab_comments -- 查询所有用户的表,视图等select * from user_tab_comments    ...

  7. Js里头的对象字面量

    JavaScript 对象字面量 在编程语言中,字面量是一种表示值的记法.例如,"Hello, World!" 在许多语言中都表示一个字符串字面量(string literal ) ...

  8. 洛谷P4721 【模板】分治 FFT(分治FFT)

    传送门 多项式求逆的解法看这里 我们考虑用分治 假设现在已经求出了$[l,mid]$的答案,要计算他们对$[mid+1,r]$的答案的影响 那么对右边部分的点$f_x$的影响就是$f_x+=\sum_ ...

  9. 三、Jmeter--HTTP请求默认值(HTTP Request Defaults)和访问地址参数化

    一.HTTP请求默认值(HTTP Request Defaults) 1. 在本地搭建了一个wordpress开源论坛,那么我每次访问论坛的地址(服务器名称或IP)是不变的,端口也是不变的,协议也是不 ...

  10. ajax中error函数参数详解

    xhr.status和error函数中的status是不一样的,error函数中的status主要包括:"success"."notmodified".&quo ...