JS: javascript 和我們的用戶進(jìn)行動(dòng)態(tài)交互
JS在IOS開發(fā)中的使用(以UIWebView為橋梁)
通過UIWebView的兩個(gè)代理方法實(shí)現(xiàn):
1. OC里面執(zhí)行JS代碼 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- (void)webViewDidFinishLoad:(UIWebView *)webView{}
2. JS調(diào)用OC的方法 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:
JS可以移除網(wǎng)頁中的任何元素:?
1)找到你需要移除的元素,通過document調(diào)用它的方法來查詢對(duì)應(yīng)的元素 ? ? ? ??
?標(biāo)簽名:document.getElementsByTagName()
?class名:document.getElementsByClassName()
2)寫JS代碼移除找到的元素
-查找到他的父控件
downLoadAppElement.parentNode
-然后再刪掉它自己
downLoadAppElement.parentNode.removeChild(downLoadAppElement);
舉例:大眾點(diǎn)評(píng) https://m.dianping.com/tuan/deal/5501525 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
需求:去除下面圖片中的綠色框內(nèi)的部分
1、去掉header這個(gè)元素
-查詢到它
var headerTag = document.getElementsByTagName('header')[0];
-刪掉
headerTag.parentNode.removeChild(headerTag);
2、去掉footer-btn-fix這個(gè)元素
-查詢到它
var footerBtnFixTag = document.getElementsByClassName('footer-btn-fix')[0];
-刪掉
footerBtnFixTag.parentNode.removeChild(footerBtnFixTag);
3、去掉footer這個(gè)元素
-查詢到它
var footerTag = document.getElementsByClassName('footer')[0];
-刪掉
footerTag.parentNode.removeChild(footerTag);
結(jié)果瀏覽:
4、給我們的植物大戰(zhàn)僵尸添加點(diǎn)擊事件
-找到我們那張圖片
var headbarTag = document.getElementsByClassName('headbar')[0];
-給其添加點(diǎn)擊事件
headbarTag.onclick = function() { window.location.; }