2010-08-01 25 views
0

我有一個div內的文字。我希望iPad上的文字可以選擇(複製/粘貼)。同時我希望能夠處理一個onclick事件。 這似乎不能很好地結合在一起。只要div可點擊,它就不可選。ipad中的文本選擇html

有沒有人知道解決這個問題的方法?

<html> 
<head> 
    <script> 

function run() { 

    // do some stuff here... 
} 


</script> 
</head> 
<body> 
    <!-- removing this onclick makes the div selectable --> 
    <div onclick="run()"> 
    <p>AAA aaaa aaaa aaaa<p> 
    <p>bbbbb bbbb BBBBB</p> 
    <div> 
</body> 

回答

0

您應該使用的事件處理程序適用於iOS的網絡互動:

// Replace "document" with the element you want it to apply 
// to through getElementById("anId") 

document.addEventListener("touchstart", run, false); 

這將調用run()中,當觸摸已經開始。

onclick,onmousedown等默認方法在iPhone,iPod touch和iPad上表現怪異。

更多here

+0

謝謝。 Ontouchstart的確有訣竅。 – Jan 2010-08-01 10:57:14