JavaScript DOM编程艺术 笔记

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 styleElementSiblings(tag,theclass){
    if (!document.getElementsByName) return false;
    var elems = document.getElementsByTagName(tag);
    for (var i = 0; i, elems.length; i++) {
        var elem = getNextElement(elems[i].nextSibling);
        addClass(elem, theclass);
    }
}

-------------

 function moveElement(elementID,final_x,final_y,interval){
        if(!document.getElementById) return false;
        if(!document.getElementById("message")) return false;
        var elem=document.getElementById(elementID);
        var xpos=parseInt(elem.style.left);
        var ypos=parseInt(elem.style.top);
        if(xpos==final_x && ypos== final_y){
            return true;
        }
        if(xpos<final_x){
            xpos++;
        }
        if(xpos>final_x){
            xpos--;
        }
        if(ypos<final_y)
        {
            ypos++;
        }
        if(ypos>final_y)
        {
            ypos--;
        }
        elem.style.left=xpos+"px";
        elem.style.top=ypos+"px";
        var repeat="moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
        movement=setTimeout(repeat,interval);
    }


为链接设置快速访问键
如何设置快速访问键并没有一定的规定,但一些比较基本的快速访问键都有约定俗成的设置办法,对此感兴趣的读者可以浏览 http://www.clagnut.com/blog/193,一般来说,accesskey=1对应着一个“返回本站主页”的链接;accesskey=“2”对应着一个“后退到前一页面”的链接;accesskey=“4”对应着一个“打开本站的搜索页面/表单”的链接;accesskey=“9”对着一个“本站联系办法”的链接;accesskey=“0”对应着一个“查看本站的快速访问键”的链接
UK Government Shortcuts
Access keyTarget
SSkip navigation
1Home page
2What’s new
3Site map
4Search
5FAQs
6Help
7Complaints procedure
8Terms and conditions
9Feedback form
0Access key details

WebAIM provides similar shortcuts:

WebAIM Shortcuts
Access keyTarget
1Home page
2Skip navigation
3Printer-friendly version
4Search

These almost match with the access keys used by Mark Pilgrim (accessibility evangelist):

Dive Into Mark Shortcuts
Access keyTarget
1Home page
2Skip navigation
4Search
0Access key details

And finally, the accessibility magazine Made For All (now sadly no more) uses a few different shortcuts:

Made For All Shortcuts
Access keyTarget
1Home page
2News
3Previous issues
4Resources
5About
0Access key details

So there’s a fair bit of overlap between sites. The use of numbers is sensible as software often uses letters for its own shortcuts, particularly for access to the command menu. Letters also make more sense when dealing with forms (think shortcuts in dialog boxes). So the main bone of contention appears to be skip nav. Here’s a few samples:

Skip Nav Shortcuts Across the Web
ShortcutWeb Site
2Dive Into Mark
2Zeldman
2WebAIM
9Cinnamon Interactive
CClagnut
CAccessify
SUK Government

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值