本文實(shí)例為大家分享了JS新浪微博分享功能,供大家參考,具體內(nèi)容如下
<!DOCTYPE html><html xmlns:wb="http://open.weibo.com/wb"><head> <meta charset="utf-8"> <title>javaScript實(shí)現(xiàn)選中文字提示新浪微博分享的效果</title> <style type="text/css"> #div1{ position: absolute; left: 0;top: 0; display: none;} </style></head><body> <p id="txt"> 一直對(duì)json的使用方法迷迷糊糊,知道一些簡(jiǎn)單的使用方法,有時(shí)用起來(lái)非常easy把自己搞混。今天專(zhuān)門(mén)查了一下相關(guān)的JSON的資料及使用方法,總結(jié)記錄下來(lái)。JSON并非一種編程語(yǔ)言。能夠理解成它是一種數(shù)據(jù)格式。盡管具有同樣的語(yǔ)法形式。可是JSON并不屬于JavaScript。并且。并非全部的JavaScript才使用JSON,非常多編程語(yǔ)言都有針對(duì)JSON的解析器和序列化器。JSON的語(yǔ)法能夠表示三種類(lèi)型值: </p> <div id="div1"><img src="https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=163431486,1136892253&fm=58"></div> <script type="text/javascript"> window.onload=function(){ function selectText(){ if(document.selection){ //兼容ie return document.selection.createRange().text; } else{ //標(biāo)準(zhǔn)的獲取方法 return window.getSelection().toString(); } } var oTxt = document.getElementById('txt'); var oDiv = document.getElementById('div1'); oTxt.onmouseup = function(ev){ var ev =ev||window.event; var top = ev.clientY; var left = ev.clientX; if(selectText().length>10){ console.log(selectText()) setTimeout(function(){ oDiv.style.display = 'block'; oDiv.style.left =left+'px'; oDiv.style.top = top +'px'; },1000) } else{ oDiv.style.display = 'none'; } }; oTxt.onclick =function(ev){ var ev =ev||window.event; ev.cancelBubble = true; } document.onclick = function(){ oDiv.style.display = 'none'; }; //點(diǎn)擊分享的實(shí)現(xiàn) oDiv.onclick = function(){ window.location.+selectText()+window.location.href; } } </script></body></html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注