码迷,mamicode.com
首页 > 其他好文 > 详细

【DOM编程艺术】综合示例

时间:2014-04-30 15:05:39      阅读:356      评论:0      收藏:0      [点我收藏+]

标签:com   http   blog   style   class   div   img   code   java   log   c   

index.html

mamicode.com,码迷
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Jay Skript And The Domsters</title>
  <script src="scripts/modernizr-1.6.min.js"></script>
  <link rel="stylesheet" media="screen" href="styles/basic.css" />
</head>
<body>
  <header>
    <img src="images/logo.gif" alt="Jay Skript and the Domsters" />
    <nav>
      <ul>
        <li><a href="index.html">Home</a></li>
        <li><a href="about.html">About</a></li>
        <li><a href="photos.html">Photos</a></li>
        <li><a href="live.html">Live</a></li>
        <li><a href="contact.html">Contact</a></li>
      </ul>
    </nav>
  </header>
  <article>
    <h1>Welcome</h1>
    <p id="intro">Welcome to the official website of Jay Skript and the Domsters. Here, you can <a href="about.html">learn more about the band</a>, view <a href="photos.html">photos of the band</a>, find out about <a href="live.html">tour dates</a> and <a href="contact.html">get in touch with the band</a>.</p>
  </article>
  <script src="scripts/global.js"></script>
</body>
</html>
mamicode.com,码迷

global.js

mamicode.com,码迷
function addLoadEvent(func){
    var oldonload = window.onload;
    if(typeof window.onload != ‘function‘){
        window.onload = func;
    }else{
        window.onload = function(){
            oldonload();
            func();
        }
    }    
}

function insertAfter(newElement,targetElement){
    var parent = targetElement.parentNode;
    if( parent.lastChild == targetElement){
        parent.appendChild(newElement);
    }else{
        parent.insertBefore(newElement,targetElement.nextSibling);
    }
}

function addClass(element,value){
    if(!element.className){
        element.className = value;
    }else{
        newClassName = element.className;
        newClassName += ‘ ‘;
        newClassName += value;
        element.className = newClassName;
    }
}

function highlightPage(){
    if( !document.getElementById) return false;
    if( !document.getElementsByTagName ) return false;
    var headers = document.getElementsByTagName(‘header‘);
    if( headers.length == 0) return false;
    var navs = headers[0].getElementsByTagName(‘nav‘);
    if( navs.length == 0 ) return false;
    var links = navs[0].getElementsByTagName(‘a‘);
    var url = window.location.href;
    for(var i=0;i<links.length;i++){
        var linkurl = links[i].getAttribute(‘href‘);
        if( url.indexOf(linkurl) != -1 ){
            links[i].setAttribute(‘href‘,‘#‘);
            links[i].className = ‘here‘ ;
        }
    }
}
addLoadEvent(highlightPage);
mamicode.com,码迷

 

【DOM编程艺术】综合示例,码迷,mamicode.com

【DOM编程艺术】综合示例

标签:com   http   blog   style   class   div   img   code   java   log   c   

原文地址:http://www.cnblogs.com/positive/p/3699491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!