Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

qqcc1388/ObjcInsetJavaScriptDemo

Repository files navigation

###项目中有这样一种需求,给html5网页中图片添加点击事件,并且弹出弹出点击的对应的图片,并且可以保持图片到本地 ###应对这样的需求你可能会想到很多方法来实现。

  1. 最简单的方法就是在html5中添加图片的onClick方法,并把图片的src和index传过来。这种方法虽然能够很好的解决这个问题,但是还需要前端代码的支持
  2. 使用WebviewJavascripBridge添加objc和js交互的方法,通过调用方法来实现效果,缺点是需要用到第三方,并且同样也需要前端代码的支持
  3. 第三种也就是今天这里要着重介绍的方法:objc中动态注入JavaScript代码,动态给img标签添加onClick事件。话不多说,直接上代码

html代码

<!DOCTYPE html>
<html>
 <head>
 <meta charset="utf-8" />
 <title>测试demo</title>
 <style type="text/css">
 img {
 width: 100%;
 }
 </style>
 </head>
 <body>
 <p>内容测试我是详情内容1</p>
 <img src="http://img1.cyzone.cn/uploadfile/2017/0602/20170602094901601.jpg">
 <p>内容测试我是详情内容2</p>
 <p>内容测试我是详情内容3</p>
 <img src="http://img1.cyzone.cn/uploadfile/2017/0602/20170602094902133.jpg">
 <p>内容测试我是详情内容4</p>
 <img src="http://img1.cyzone.cn/uploadfile/2017/0602/20170602094902734.jpg">
 <p>内容测试我是详情内容5</p>
 
 </body>
</html>

objc代码

About

ObjcInsetJavaScriptDemo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /