当前位置:编程学习 > JS >>

js常用实例

1.网页上显示qq的状态,点击后即可聊天,无须是好友

<a target="_blank" href="http://wpa.qq.com/msgrd?V=1&Uin=*******&Site=ioshenmue&Menu=yes"><img src="http://wpa.qq.com/pa?p=1:*******:1" border="0"></a>

‘*’处换成在线的qq号即可

 

两种状态

 

点击后:

 

 

2.划词百度搜索功能


 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>

<SCRIPT language=javascript>
<!--
document.body.onload=adddiv;
document.onmousedown=recordobj;
document.ondblclick=dbclick;
document.onmouseup=showselect;
var starobj,isdb=false,allow=true;
function isallow()
{
if(allow){
allow=false;
alert('划词搜索已关闭');
}
else{
allow=true;
alert('恭喜你,划词搜索已为你打开,选中任意词组或字可以进行搜索!');
}
}
function dbclick()
{
isdb=true;
}
function recordobj()
{
starobj=event.srcElement;
}
function showselect() {
var str="";
if(event.srcElement.tagName!="A"&&event.srcElement.tagName!="INPUT"&&event.srcElement==starobj&&!isdb&&allow)
{
var oText=document.selection.createRange();
if(oText.text.length>0)
{
str=oText.text;
oText.text="BuB"+oText.text+"EuE";
}

oText.select();
event.srcElement.innerHTML=event.srcElement.innerHTML.replace("BuB","<u style='FONT-WEIGHT: bold;COLOR: #ff3366'>").replace("EuE","</u>");
}
searchgoogle(str)
isdb=false;
}
function searchgoogle(str)
{
var obj=document.getElementById("searchgoogle");
if(str.length>0)
{
obj.style.display="block";
obj.style.position="absolute";
obj.style.zindex=999;
obj.style.posTop=document.body.scrollTop+event.y-25;
obj.style.posLeft=document.body.scrollLeft+event.x+5;
obj.style.widht=80;
obj.innerHTML="<a target=_blank href=http://www.baidu.com/baidu?word="+str+" style='BORDER-RIGHT: #fff1ca thin solid; BORDER-TOP: #fff1ca thin solid; FONT-WEIGHT: bold; BORDER-LEFT: #fff1ca thin solid; CLIP: rect(auto auto auto auto); COLOR: #666666; BORDER-BOTTOM: royalblue thin solid; BACKGROUND-COLOR: #fff1ca; TEXT-DECORATION: none'>这是什么?</a>";
}
else
{
obj.style.display="none";
}
}
function adddiv()
{
var mobj = document.createElement("div");
mobj.id="searchgoogle";
document.body.appendChild(mobj);
}
//BY QPSH.COM-->
</SCRIPT>
<INPUT type="button" onclick="isallow()" value="关闭/打开划词功能">

篮球,dota

</body>
</html>
 作者:wm5920

补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,