2014-02-14 43 views
0

我在UIWebView上運行JavaScript,但不幸的是它不工作。UIWebView使用Javascript來選擇元素

我當用戶在網頁上觸摸我想獲取觸摸元素的文本,並突出顯示該元素。

//試過這種

[webView stringByEvaluatingJavaScriptFromString:@"document.onclick = function (e) {e.target.style.background='#ff3355';   };"]; 

//試過這種

[webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].onclick = function (e) {e.target.style.background='#ff3355';   };"]; 

Hopever這是工作,當我檢查網絡瀏覽器。

http://jsfiddle.net/D9NC3/62/

有人請建議什麼是使用正確的方法是什麼?

+0

有誰知道答案? – Nitya

回答

0

我找到答案!

[webView stringByEvaluatingJavaScriptFromString:@「document.ontouchstart = function(e){e.target.style.background ='#ff3355';};」];

相關問題