JavaScript实现选中文字提示新浪微博分享效果

<!DOCTYPE html> <html xmlns:wb="http://open.weibo.com/wb"> <head> <meta charset="utf-8"> <title>javaScript实现选中文字提示新浪微博分享的效果</title> <style type="text/css"> #div1{ position: absolute; left: 0;top: 0; display: none;} </style> </head> <body> <p> 一直对json的使用方法迷迷糊糊,知道一些简单的使用方法,有时用起来非常easy把自己搞混。今天专门查了一下相关的JSON的资料及使用方法,总结记录下来。JSON并非一种编程语言。能够理解成它是一种数据格式。尽管具有同样的语法形式。可是JSON并不属于JavaScript。并且。并非全部的JavaScript才使用JSON,非常多编程语言都有针对JSON的解析器和序列化器。JSON的语法能够表示三种类型值: </p> <div><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{ //标准的获取方法 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'; }; //点击分享的实现 oDiv.onclick = function(){ window.location.href='http://service.weibo.com/share/share.php?url=http%3A%2F%2Flocalhost%3A63342%2Fjs2%2Fpicscroll.html&type=icon&language=zh_cn&searchPic=true&style=simple'+selectText()+window.location.href; } } </script> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyxgyw.html