expand_collapse.js
来自「Web标准的创造力-Web.Standards.Creativity.pdf」· JavaScript 代码 · 共 72 行
JS
72 行
addLoadListener(initExpandCollapse);
function initExpandCollapse()
{
var modules = [document.getElementById("modules1"), document.getElementById("modules2")];
for (var i in modules)
{
var h2s = modules[i].getElementsByTagName("h2");
for (var i = 0; i < h2s.length; i++)
{
var newA = document.createElement("a");
newA.setAttribute("href", "#");
newA.setAttribute("title", "Expand/Collapse");
attachEventListener(newA, "mousedown", mousedownExpandCollapse, false);
newA.onclick = clickExpandCollapse;
var newImg = document.createElement("img");
newImg.setAttribute("src", "images/expand_collapse.gif");
newImg.setAttribute("alt", "Expand/Collapse");
newA.appendChild(newImg);
h2s[i].appendChild(newA);
}
}
return true;
};
function mousedownExpandCollapse(event)
{
if (typeof event == "undefined")
{
event = window.event;
}
if (typeof event.stopPropagation != "undefined")
{
event.stopPropagation();
}
else
{
event.cancelBubble = true;
}
return true;
};
function clickExpandCollapse()
{
if (!hasClass(this.parentNode.parentNode, "collapsed"))
{
addClass(this.parentNode.parentNode, "collapsed");
}
else
{
removeClass(this.parentNode.parentNode, "collapsed");
}
return false;
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?