總結(jié):文字選中IE和其他瀏覽器不一樣
在IE中文字選中后鼠標(biāo)抬起,圖片顯現(xiàn)觸發(fā)有點(diǎn)快所以用定時(shí)器。
<!DOCTYPE html><html><head><meta charset=utf-8 /><title></title><script type="text/javascript" src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script><style type="text/css">*{padding: 0;margin: 0;}#p1{width: 300px;}#div1{display: none;position: absolute;}img{width:26px;height:26px;}</style></head><body><p id="p1"> 文字的選中功能是不太常用的功能,多出現(xiàn)在文本編輯器中,或是文本域之類的光標(biāo)處理上。所以呢,使用的一些屬性也并不是常見(jiàn)的。在IE瀏覽器下使用的是createTextRange而Firefox/chrome等現(xiàn)代瀏覽器下使用的是setSelectionRange。</p><div id='div1'><img src='http://cdn.attach.qdfuns.com/notes/pics/201701/23/221744ud9ggjjjgg85e90m.gif.editor.gif'></div><script type="text/javascript">function selectText(){ if(document.selection){ //IE return document.selection.createRange().text }else{ //ff chrom return window.getSelection().toString() }}var oP=document.getElementById('p1')var oDiv=document.getElementById('div1')oP.onmouseup=function(ev){ var ev=ev||event var left=ev.clientX var top=ev.clientY if(selectText().length>10){ setTimeout(function(){ oDiv.style.display='block'; oDiv.style.left=left+'px' oDiv.style.top=top+'px' },100) }else{ oDiv.style.display='none'; }}//點(diǎn)擊oP阻止冒泡到document上oP.onclick=function(ev){ var ev=ev||window.event ev.cancelBubble=true}document.onclick=function(){ oDiv.style.display='none';}</script></body></html>以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持武林網(wǎng)!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注