什么是JavaScript while循环在这里做什么?

ben*_*e89 1 javascript while-loop

这里的JavaScript代码是什么,特别是while循环:

function setAjaxLinks(){
    var links = document.body.getElementsByTagName("a");
    var linkL = links.length;

    while (linkL--) {
        if (!links[linkL].href.match('#')) {
            mj.pageLoad(links[linkL]);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道"mj"并不意味着什么,但一般的要点是什么?

Mar*_*sen 5

它遍历页面上从最后到第一个(递减)的所有链接(a-tags).

如果它找到一个没有#符号mj.pageLoad的链接,它会使用相关链接作为参数调用该函数.

这是一个打击:

function setAjaxLinks(){
    //find all <a> tag elements on the page
    var links = document.body.getElementsByTagName("a");
    //get the amount of <a> tags on the page
    var linkL = links.length;
    //loop over all <a> tags on the page from last to first
    while (linkL--) {
        //if the href attribute on the current <a> tag has a # sign in it
        if (!links[linkL].href.match('#')) {
            //then call this function (and from the name of the function convert it to an ajax call) 
            mj.pageLoad(links[linkL]);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)