<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
         @import"dy.css";
         @import"hide.css";
</style><script type="text/javascript" src="DOMhelp.js"></script>
<script type="text/javascript" src="sc.js"></script>
</head><body>
<h3>contact details</h3>
<address>aaaaaaa<br/>
         bbbbbb<br/>
 cccccc<br/>
 dddddd<br/>
</address></body>
</html>
.hide{ position:absolute;
       top:0;
   left:-9999px;
   height:0;
   }
dy.css/* CSS Document */
*{
    margin:0;
padding:0;
}
body{
         font-family:Arial, Helvetica, sans-serif;
 font-size:small;
 padding:2em;
 }
/* js disabled*/
address{
          background:#ddd;
  border:1px solid #999;
  border-top:none;
  font-style:normal;
  padding:.5em;
  width:15em;
  }
h3{ 
     border:1px solid #000;
 color:#fff;
 background:#369;
 padding:.2em .5em;
 width:15em;
 font-size:1em;
 }
/* js enable */
body.dynamic address{
          background:#fff;
  border:none;
  font-style:normal;
  padding:.5em;
  border-top:1px solid #ccc;
  }
body.dynamic h3{
    padding-bottom:.5em;
background:#fff;
border:none;
}
body.dynamic h3 a{
color:#369;
}
var sc={

hidingClass:'hide',
DOMClass:'dynamic',
init:function(){
DOMhelp.cssjs('add',document.body,sc.DOMClass);
sc.head=document.getElementsByTagName('h3')[0];
sc.ad=DOMhelp.closestSibling(sc.head,1);
sc.ad.style.display='none';
DOMhelp.cssjs('add',sc.ad,sc.hidingClass);
var t=DOMhelp.getText(sc.head);
var collapselink=DOMhelp.createLink('#',t);
sc.head.replaceChild(collapselink,sc.head.firstChild);
DOMhelp.addEvent(collapselink,'click',sc.peekaboo,false);
collapselink.onclick=function(){return;}

},
peekaboo:function(e){
         if(DOMhelp.cssjs('check',sc.ad,sc.hidingClass))
 {
 DOMhelp.cssjs('remove',sc.ad,sc.hidingClass);
 }else{
 DOMhelp.cssjs('add',sc.ad,sc.hidingClass);
 }
 DOMhelp.cancelClick(e);
}
}
DOMhelp.addEvent(window,'load',sc.init,false);
主要想问下dy.css那个文件中*{
    margin:0;
padding:0;
}
什么意思干嘛加*啊?
body.dynamic address{
       。。
       。。
}这种写法是什么意思啊?
hidingClass:'hide',
DOMClass:'dynamic',
做什么用

JS可用时,DOMhelp.cssjs('add',document.body,sc.DOMClass);具体是什么意思怎么和dy.css那个文件联系起来理解?

解决方案 »

  1.   

    主要想问下dy.css那个文件中*{ 
        margin:0; 
    padding:0; 

    什么意思干嘛加*啊?*代表通配符~·表示全部html标签用这个样式~·
    body.dynamic address{ 
          。。 
          。。 
    }这种写法是什么意思啊?表示body标签里class属性为dynamic的标签里<address>标签
    DOMhelp.cssjs把这个放过发上来~·
      

  2.   

    /*
     DOMhelp 1.0
     written by Chris Heilmann
     http://www.wait-till-i.com
     To be featured in "Beginning JavaScript for Practical Web Development, Including  AJAX" 
    */
    DOMhelp={
     debugWindowId:'DOMhelpdebug',
     init:function(){
      if(!document.getElementById || !document.createTextNode){return;}
     },
     lastSibling:function(node){
      var tempObj=node.parentNode.lastChild;
      while(tempObj.nodeType!=1 && tempObj.previousSibling!=null){
       tempObj=tempObj.previousSibling;
      }
      return (tempObj.nodeType==1)?tempObj:false;
     },
     firstSibling:function(node){
      var tempObj=node.parentNode.firstChild;
      while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
       tempObj=tempObj.nextSibling;
      }
      return (tempObj.nodeType==1)?tempObj:false;
     },
     getText:function(node){
      if(!node.hasChildNodes()){return false;}
      var reg=/^\s+$/;
      var tempObj=node.firstChild;
      while(tempObj.nodeType!=3 && tempObj.nextSibling!=null || reg.test(tempObj.nodeValue)){
       tempObj=tempObj.nextSibling;
      }
      return tempObj.nodeType==3?tempObj.nodeValue:false;
     },
     setText:function(node,txt){
      if(!node.hasChildNodes()){return false;}
      var reg=/^\s+$/;
      var tempObj=node.firstChild;
      while(tempObj.nodeType!=3 && tempObj.nextSibling!=null || reg.test(tempObj.nodeValue)){
       tempObj=tempObj.nextSibling;
      }
      if(tempObj.nodeType==3){tempObj.nodeValue=txt}else{return false;}
     },
     createLink:function(to,txt){
      var tempObj=document.createElement('a');
      tempObj.appendChild(document.createTextNode(txt));
      tempObj.setAttribute('href',to);
      return tempObj;
     },
     createTextElm:function(elm,txt){
      var tempObj=document.createElement(elm);
      tempObj.appendChild(document.createTextNode(txt));
      return tempObj;
     },
     closestSibling:function(node,direction){
      var tempObj;
      if(direction==-1 && node.previousSibling!=null){
       tempObj=node.previousSibling;
       while(tempObj.nodeType!=1 && tempObj.previousSibling!=null){
         tempObj=tempObj.previousSibling;
       }
      }else if(direction==1 && node.nextSibling!=null){
       tempObj=node.nextSibling;
       while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
         tempObj=tempObj.nextSibling;
       }
      }
      return tempObj.nodeType==1?tempObj:false;
     },
     initDebug:function(){
      if(DOMhelp.debug){DOMhelp.stopDebug();}
      DOMhelp.debug=document.createElement('div');
      DOMhelp.debug.setAttribute('id',DOMhelp.debugWindowId);
      document.body.insertBefore(DOMhelp.debug,document.body.firstChild);
     },
     setDebug:function(bug){
      if(!DOMhelp.debug){DOMhelp.initDebug();}
      DOMhelp.debug.innerHTML+=bug+'\n';
     },
     stopDebug:function(){
      if(DOMhelp.debug){
       DOMhelp.debug.parentNode.removeChild(DOMhelp.debug);
       DOMhelp.debug=null;
      }
     },
     getKey:function(e){
      if(window.event){
           var key = window.event.keyCode;
         } else if(e){
           var key=e.keyCode;
         }
      return key;
     },
    /* helper methods */
     getTarget:function(e){
      var target = window.event ? window.event.srcElement : e ? e.target : null;
      if (!target){return false;}
      while(target.nodeType!=1 && target.nodeName.toLowerCase()!='body'){
       target=target.parentNode;
      }
      return target;
     },
     stopBubble:function(e){
      if(window.event && window.event.cancelBubble){
       window.event.cancelBubble = true;
      } 
      if (e && e.stopPropagation){
       e.stopPropagation();
      }
     },
     stopDefault:function(e){
      if(window.event && window.event.returnValue){
       window.event.returnValue = false;
      } 
      if (e && e.preventDefault){
       e.preventDefault();
      }
     },
     cancelClick:function(e){
      if (window.event){
       window.event.cancelBubble = true;
       window.event.returnValue = false;
      }
      if (e && e.stopPropagation && e.preventDefault){
       e.stopPropagation();
       e.preventDefault();
      }
     },
     addEvent: function(elm, evType, fn, useCapture){
      if (elm.addEventListener){
       elm.addEventListener(evType, fn, useCapture);
       return true;
      } else if (elm.attachEvent) {
       var r = elm.attachEvent('on' + evType, fn);
       return r;
      } else {
       elm['on' + evType] = fn;
      }
     },
     cssjs:function(a,o,c1,c2){
      switch (a){
       case 'swap':
        o.className=!DOMhelp.cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
       break;
       case 'add':
        if(!DOMhelp.cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
       break;
       case 'remove':
        var rep=o.className.match(' '+c1)?' '+c1:c1;
        o.className=o.className.replace(rep,'');
       break;
       case 'check':
        var found=false;
        var temparray=o.className.split(' ');
        for(var i=0;i<temparray.length;i++){
         if(temparray[i]==c1){found=true;}
        }
        return found;
       break;
      }
     },
        safariClickFix:function(){
          return false;
        }
    }
    DOMhelp.addEvent(window, 'load', DOMhelp.init, false);
      

  3.   

    body中没有dynamic。
    我觉得和这个有关DOMClass:'dynamic',但是具体我说不出它是什么意思。
    我觉得和css有关
      

  4.   

    body.dynamic address{ 
          。。 
          。。 
    }的语法规则是什么我不知道?主要想知道它的语法规则
      

  5.   

    这个的确跟DOMClass:'dynamic'有关,由DOMhelp.cssjs中引用,即o.className=...(o为document.body),这时body就引用上css中dynamic的class,从而改变了address标签的的样式