日期:2014-05-16  浏览次数:20331 次

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 searchbaidu(str)
{
var obj=document.getElementById("searchbaidu");
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="searchbaidu";
document.body.appendChild(mobj);
}
//BY QPSH.COM-->
</SCRIPT>
<INPUT type="button" onclick="isallow()" value="关闭/打开划词功能">

篮球,dota

</body>
</html>

 

3.标签切换(参考WWW.QPSH.COM)

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网页特效 WWW.QPSH.COM</title>
<style>
body {
 font-family: "宋体";
 font-size: 12px;
 color: #525252;
}
td {
 font-family: "宋体";
 font-size: 12px;
 color: #525252;
}
a:link {
 color: #525252;
 font-size: 12px;
 text-decoration: none;
}
a:visited{
 color: #525252;
 font-size: 12px;
 text-decoration: none;
}
a:hover {
 co