<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
*{margin:0 auto;}
div{
margin:50px auto;
border:1px solid #ccc;
border-radius:6px;
width:500px;
height:300px;
padding:10px;
}
#nav_menu{
width:100px;
height:30px;
border-radius:6px;
border:1px solid blue;
color:red;
line-height:30px;
text-align:center;
font-size:14px;
position:fixed;
left:0px;
top:0px;
display:none;
background:#fff;
}
#nav_menu button{
border:none;
background:transparent;
cursor:pointer;
}
</style>
</head>
<body>
<div id='content' onmouseup='selec()'>
前劳斯莱斯规划履行官吉尔斯泰勒现已搬到一汽轿车部门红旗,从事豪华车的出产。该品牌转换为“红旗”,出产一些最贵重的中国轿车。贾尔斯泰勒具有26年轿车规划生计,曾先后服务于雪铁龙、捷豹和劳斯莱斯品牌,主导规划了雪铁龙C3概念车和捷豹XJ、XK等车型。来源:百家号
</div>
<p id='nav_menu'><button onclick="copyText()">复制</button>|<button onclick="seatchText()">搜索</button></p>
<script type="text/javascript">
var sele_text=window.getSelection();
var def_p=document.getElementById('nav_menu');
function selec(event){
var e=event||window.event;
var m_x=e.clientX;
var m_y=e.clientY;
console.log(sele_text);
if(sele_text.toString().length>0){
def_p.style.display='block';
def_p.style.left=m_x+'px';
def_p.style.top=m_y+'px';
}
else{
def_p.style.display='none'; //alert(sele_text);
}
}
function copyText(){
document.execCommand('Copy');
def_p.style.display='none';
}
function seatchText(){
window.location.href="https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_4_dg&wd="+sele_text;
}
</script>
</body>
</html>