Js應用整理

來源:互聯網
上載者:User

由於最近項目需要,故對Js代碼作出整理:
1. 怎樣自動檢測使用者有沒有安裝realplayer的外掛程式,並能自動安裝它?
           classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA  VIEWASTEXT> 
           
           
           
           
           
           
          http://192.168.0.7:8000/plugin.rpm"> 
           
           
           
           
           
           
           
            
 
自己會檢測 
--------------------------------------------------------------- 
 
檢測: 
  \n'); 
 
 
if  (RealMode    ¦  ¦  RealPlayerG2    ¦  ¦  RealPlayer5    ¦  ¦  RealPlayer4)   

           alert("RealPlayer  plug-in  is  installed."); 

else   

           alert("RealPlayer  plug-in  is  not  installed."); 
}             
 
--------------------------------------------------------------- 
 
           classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA  VIEWASTEXT> 
--------------------------------------------------------------- 
 
 
2.用JavaScript實現網頁上的浮動廣告
以下這段代碼可放在之間,其間我加入了一些注釋(即“//”後的文字及“”之間的文字)。
  

  

  
  

   http://www.5dmedia.com/bbs"> src='../qqkk2000.gif' border="0" height="60" width="60">
  

  在這裡,你可以設定x、y的值來設定所固定層的位置,改變setTimeout("MoveLayer('AdLayer');", 20)中20的值為你希望調用MoveLayer()的時間間隔。還有要注意的是,使用的圖片最好為透明背景的gif圖,以使圖片的背景顏色不至於遮住後面的的內容。
3.javascript樹的Demo 原始碼
檔案結構如下
DemoTree
|------MyTree.js
|------tree,html
|------image(存放用到的相關圖片)

MyTree.js 內容如下
--------------------------------------------------

var Icon = {
folderOpen: "folderOpen.gif",
folderClose: "folderClose.gif",
fileimage: "file.gif",
plus: "plus.gif",
minus: "minus.gif",
blank: "blank.gif"
}

//set the directory of the pictures
setImagePath = function(sPath) {
for(o in Icon){
tmp = sPath + Icon[o];
Icon[o] = new Image();
Icon[o].src = tmp;
}
}

window.Tree = [];

function MyTree(){
this.id = window.Tree.length;
window.Tree[this.id] = this;
this.target = "_self";
this.nodes = {0:{id:0, superID: -1, Text: null, nodeType: null, childrenNodes: new Array()}};
}

var tr = MyTree.prototype; // create a instence of the MyTree

tr.add = function(key, superid, text, nodetype){
this.nodes[key] = {id: key, superID:superid, Text: text, nodeType: nodetype, childrenNodes: new Array()};

var ch = this.getNode(superid).childrenNodes;
ch[ch.length] = this.nodes[key];
}

// get a certain node by id
tr.getNode = function(key){
if (typeof this.nodes[key] != "undefined")
{
return this.nodes[key];
}
return null;
}

//get a node's parent
tr.getParent = function(key){
if(this.getNode(key) != null){
var skey = this.getNode(key).superID;
if(typeof this.nodes[skey] != "undefined"){
return this.getNode(skey);
} else {
return null;
}
}else{
return null;
}
}

//the status of the children
tr.hasChildren = function(key){
return this.getNode(key).childrenNodes.length > 0
}

//get root
tr.getRoot = function(key) {
if(key == 0)
return this.getNode(key);
var par = this.getParent(key);
if (this.getNode(key).id == 0)
{
return this.getNode(key);
}
else
{
return this.getRoot(par.id);
}
}

//draw a node
tr.drawNode = function(key){
var html = "";
var node = this.getNode(key);
var rootID = this.getRoot(key);
var hc = this.hasChildren(key);
//html += '

' +this.drawIndent(key) + '';
html += '

' +this.drawIndent(key);
if(this.getNode(key).nodeType==true){
html += '';
} else{
html += '';
}
//html += '' +node.Text+ '

\n';
html += '' +node.Text+ '

\n';
if(hc){
var io = key == rootID.id;
html += ('

\n');
html += this.drawChild(key);
html += '

\n';
}
return html;
}

//draw indent
tr.drawIndent = function(key){
var s = ''
var ir = this.getRoot(key).id == key;
var node = this.getNode(key);
var hc = this.hasChildren(key);
if(this.getParent(key) != null)
s = hc ? '' : '';
var p = this.getParent(key);
while(p != null)
{
if(this.getParent(p.id) == null)break;
s = ('')+s;
p = this.getParent(p.id);
}
return s;
}

//draw a node's children nodes
tr.drawChild = function(key){
var node = this.getNode(key);
var html = "";
for(var i = 0; i < node.childrenNodes.length; i++){
html += this.drawNode(node.childrenNodes[i].id);
}
return html;
}

//
tr.openHandler = function(key){
var handler = document.getElementById("handler"+key);
var container = document.getElementById("container"+key);
var fimage = document.getElementById("image"+key);
if(container.style.display ==''){
container.style.display = 'none';
handler.src = Icon.plus.src;
fimage.src = Icon.folderClose.src;
}else{
container.style.display = '';
handler.src = Icon.minus.src;
fimage.src = Icon.folderOpen.src;
}
}

//
tr.openFolder = function(key){
}

tr.toString = function(key){
return this.drawChild(0);
}
-----------------------------------------
tree.html代碼如下
-----------------------------------------

4.頁面漂浮廣告
<script> 
document.write('<DIV  id=mov6  style="POSITION:  absolute;  width:  10px;  height:  10px"><OBJECT  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"  WIDTH=80  HEIGHT=80><PARAM  NAME=movie  VALUE="http://www.163.net/ad/adv/netcn/netcn_100x100.swf">  <PARAM  NAME=quality  VALUE=high>  <PARAM  NAME=bgcolor  VALUE=#FFFFFF>  <EMBED  src="http://www.163.net/ad/adv/netcn/netcn_100x100.swf"  quality=high  bgcolor=#FFFFFF    WIDTH=80  HEIGHT=80  TYPE="application/x-shockwave-flash"  PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT><img  src="http://bjad.163.net/image.ng/site=www163net&channel=163mainpage&SpaceDesc=mainpage&location=moving2"  width="1"  height="1"  border="0"></DIV>'); 
 
var  xPos  =  250; 
var  yPos  =  document.body.clientHeight; 
var  step  =  1; 
var  delay  =  20;   
var  height  =  0; 
var  Hoffset  =  0; 
var  Woffset  =  0; 
var  yon  =  0; 
var  xon  =  0; 
var  pause  =  true; 
var  interval; 
mov6.style.top  =  yPos; 
function  changePos()  { 
width  =  document.body.clientWidth; 
height  =  document.body.clientHeight; 
Hoffset  =  mov6.offsetHeight; 
Woffset  =  mov6.offsetWidth; 
mov6.style.left  =  xPos  +  document.body.scrollLeft; 
mov6.style.top  =  yPos  +  document.body.scrollTop; 
if  (yon)  { 
yPos  =  yPos  +  step; 

else  { 
yPos  =  yPos  -  step; 

if  (yPos  <  0)  { 
yon  =  1; 
yPos  =  0; 

if  (yPos  >=  (height  -  Hoffset))  { 
yon  =  0; 
yPos  =  (height  -  Hoffset); 

if  (xon)  { 
xPos  =  xPos  +  step; 

else  { 
xPos  =  xPos  -  step; 

if  (xPos  <  0)  { 
xon  =  1; 
xPos  =  0; 

if  (xPos  >=  (width  -  Woffset))  { 
xon  =  0; 
xPos  =  (width  -  Woffset); 
     } 

function  start()  { 
mov6.visibility  =  "visible"; 
interval  =  setInterval('changePos()',  delay); 

 
start(); 
</script>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.