一、運行的效果圖 1、剛開始的效果 2、運行結束後的效果 二、準備工作 1、準備一個html文件導入到oc工程中 2、jiaohu.html文件的原始內容 3、從oc語言中操作.html文件---增刪改查 1).查詢操作 2).刪除操作 3).更改操作 4).插入操作 //插入操作1 //插入操作2 ...
一、運行的效果圖
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];