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. idea下建立bootstrap项目

    环境准备: 1.创建一个static web名为bootstrapDemo 2.在bootstrapDemo文件夹下安装bower npm install bower 会自动产生node-module ...

  2. WinForm判断程序是否已经在运行,且只允许运行一个实例

    我们开发WinFrom程序,很多时候都希望程序只有一个实例在运行,避免运行多个同样的程序,一是没有意义,二是容易出错. 为了更便于使用,笔者整理了一段自己用的代码,可以判断程序是否在运行,只运行一个实 ...

  3. C++ 静态常量

    #include<iostream> #include<stdexcept> #include <map> using namespace std; class n ...

  4. HttpServletRequest获取请求得URL信息

    request对象中包含的是请求信息,当我们在浏览器地址栏上输入:http://localhost:8080/Example/AServlet?username=zhangsan,这段地址也会作为请求 ...

  5. NET Core 2.0利用MassTransit集成RabbitMQ

    NET Core 2.0利用MassTransit集成RabbitMQ https://www.cnblogs.com/Andre/p/9579764.html 在ASP.NET Core上利用Mas ...

  6. curl获取图片

    <?php set_time_limit(0); //执行30秒超时后继续执行 header("Content-type:text/html;charset=utf-8"); ...

  7. dockerfile mysql

    FROM centos6.6-mysql5.5:0.0.4 MAINTAINER syberos:wangmo RUN mv /etc/my.cnf /etc/my.cnf.bak ADD my.cn ...

  8. 配置Nginx实现负载均衡

    在关于高并发负载均衡一文中已经提到,企业在解决高并发问题时,一般有两个方向的处理策略,软件.硬件,硬件上添加负载均衡器分发大量请求,软件上可在高并发瓶颈处:数据库+web服务器两处添加解决方案,其中w ...

  9. stdin和STDIN_FILENO的区别

    STDIN_FILENO与stdin的区别: STDIN_FILENO: 1).数据类型:int 2).层次:系统级的API,是一个文件句柄,定义在<unistd.h>中. 3).相应的函 ...

  10. Celery-4.1 用户指南: Extensions and Bootsteps (扩展和Bootsteps)

    自定义消息消费者 你可能想要嵌入自定义的 Kombu 消费者来手动处理你的消息. 为了达到这个目的,celery 提供了一个 ConsumerStep bootstep 类,你只需要定义 get_co ...