http://m.haodou.com/topic-327282.html?id=327282 chrome浏览器打开
![](https://img.haomeiwen.com/i3739252/9b9c7e273b0f3503.png)
选择你要隐藏的控件
![](https://img.haomeiwen.com/i3739252/3faf10ebdce53ead.png)
![](https://img.haomeiwen.com/i3739252/b587ee5a5a69177f.png)
其中右下角中是这个控件对应的css代码,在其中添加一行display:none,这时这个选中的控件就被隐藏起来了.但是我们主要通过javascript去操作这个控件
用js代码区获取到要隐藏的控件
点击console -> 在命令行中输入要执行的代码 -> 返回执行结果
![](https://img.haomeiwen.com/i3739252/7907d891d801980f.png)
![](https://img.haomeiwen.com/i3739252/b0b7937f075762c4.png)
获取到要隐藏的元素:
![](https://img.haomeiwen.com/i3739252/913702f76ea8a1e1.png)
获取到要隐藏的元素:
![](https://img.haomeiwen.com/i3739252/7074349d79c8bd11.png)
设置获取到控件的display属性
![](https://img.haomeiwen.com/i3739252/7ead06026f935b90.png)
![](https://img.haomeiwen.com/i3739252/52138e6e03392e91.png)
UIWebView的使用:
//创建webview
self.webview= [[UIWebViewalloc] initWithFrame:self.view.frame];
[self.viewaddSubview:_webview];
//设置代理
self.webview.delegate=self;
//发送请求
[_webview loadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:@"http://m.haodou.com/topic-327282.html?id=327282"]]];
![](https://img.haomeiwen.com/i3739252/24356b752fb51730.png)
#pragmamark-UIWebViewDelegate
-(void)webViewDidFinishLoad:(UIWebView *)webView{
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('adpic')[0].style.display = 'none'"];
}
这个回调函数会在webview 请求网页成功会执行这个方法,当执行这个方法时,我们就用webview去执行屏蔽广告的js代码.
![](https://img.haomeiwen.com/i3739252/0bd7f56a1e11bee5.png)
网友评论