一、运行的效果图
1、刚开始的效果
![](https://upload-images.jianshu.io/upload_images/1491886-e979fb534ebf49f3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
2、运行结束后的效果
![](https://upload-images.jianshu.io/upload_images/1491886-080d818b6d776169.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
二、准备工作
1、准备一个html文件导入到oc工程中
2、jiaohu.html文件的原始内容
![](https://upload-images.jianshu.io/upload_images/1491886-f11ca2f19184a910.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
3、从oc语言中操作.html文件---增删改查
1).查询操作
var p = document.getElementById('word');
2).删除操作
NSString*html =@"var p = document.getElementById('word');"; NSString*html2 =@"p.remove();"; [webViewstringByEvaluatingJavaScriptFromString:html]; [webViewstringByEvaluatingJavaScriptFromString:html2];
3).更改操作
NSString*htmlUpdate =@"var change = document.getElementsByClassName('change')[0];" "change.innerHTML = '更改后的值';"; [webViewstringByEvaluatingJavaScriptFromString:htmlUpdate];
4).插入操作
//插入操作1
![](https://upload-images.jianshu.io/upload_images/1491886-39c5a1a77db18106.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
//插入操作2 NSString*htmlInsert =@"var img = document.createElement('img');" "img.src = 'img11.jpg';" "img.width = '200';" "img.height = '200';" "document.body.appendChild(img);"; [webViewstringByEvaluatingJavaScriptFromString:htmlInsert];