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=addp;
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 addp()
{
var mobj = document.createElement("p");
mobj.id="searchgoogle";
document.body.appendChild(mobj);
}
//BY QPSH.COM–>
</SCRIPT>
<INPUT type="button" onclick="isallow()" value="關閉/打開劃詞功能">

籃球,dota

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

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *