zoukankan      html  css  js  c++  java
  • 【DOM编程艺术】综合示例

    index.html

    <!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>

    global.js

    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);
  • 相关阅读:
    结巴分词 0.14 版发布,Python 中文分词库
    Lazarus 1.0.2 发布,Pascal 集成开发环境
    Android全屏 去除标题栏和状态栏
    服务器日志现 Android 4.2 传将添多项新特性
    Percona XtraBackup 2.0.3 发布
    长平狐 Android 强制设置横屏或竖屏 设置全屏
    NetBeans 7.3 Beta 发布,全新的 HTML5 支持
    CppDepend现在已经支持Linux
    GromJS 1.7.18 发布,服务器端的 JavaScript
    Apache OpenWebBeans 1.1.6 发布
  • 原文地址:https://www.cnblogs.com/positive/p/3699491.html
Copyright © 2011-2022 走看看