User:Chronowar/用户:Chronowar/sandbox2.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
function InitializationBoxElement() {
// 如果您有元数据库,它会在加载页面时运行,
// 将事件分配给按钮
//alert("InitializationBoxElement");
var i = 0; // 启动箱式计数器(?)
for (i = 0; i <= 15; i++) {
var vPt = document.getElementById("pt" + i);
if (!vPt) break;
//alert("InitializationBoxElement, trobada Metacaixa pa"+i);
var j = 1; // Inicialitzem comptador de botons dins de la caixa
var vPrIni = 0; // Pestanya visible inicial
for (j = 1; j <= 9; j++) {
var vbu = document.getElementById("pa" + i + "bu" + j);
if (!vbu) break;
//alert("InitializationBoxElement, trobat botó pa"+i+"bu"+j);
vbu.onclick = MetaBoxDisplaytab; // A cada botó assignem l'esdeveniment onclick
//alert (vbu.className);
if (vbu.className == "paBotoSel") vPrIni = j; // Si tenim un botó seleccionat, en guardem l'index
}
//alert ("pa="+i+", pr="+j+", prini="+vPrIni );
if (vPrIni === 0) { // Si no tenim cap botó seleccionat, n'agafem un aleatòriament
vPrIni = 1 + Math.floor((j - 1) * Math.random());
//alert ("Activant Pestanya a l'atzar; _pa"+i+"bu"+vPrIni +"_");
document.getElementById("pa" + i + "pr" + vPrIni).style.display = "block";
document.getElementById("pa" + i + "pr" + vPrIni).style.visibility = "visible";
document.getElementById("pa" + i + "bu" + vPrIni).className = "paBotoSel";
}
}
}
function MetaBoxDisplaytab() {
// S'executa al clicar una pestanya,
// aquella es fa visible i les altres s'oculten
var vPaNom = this.id.substr(0, 3); // A partir del nom del botó, deduïm el nom de la caixa
var vIndex = this.id.substr(5, 1); // I l'index
var i = 1;
for (i = 1; i <= 9; i++) { // busquem totes les pestanyes d'aquella caixa
//alert(vPaNom+"pr"+i);
var vprElem = document.getElementById(vPaNom + "pr" + i);
if (!vprElem) break;
if (vIndex == i) { // Si és la pestanya bona la mostrem i canviem la classe de botó
vprElem.style.display = "block";
vprElem.style.visibility = "visible";
document.getElementById(vPaNom + "bu" + i).className = "paBotoSel";
} else { // Sinó, l'ocultem i canviem la classe de botó
vprElem.style.display = "none";
vprElem.style.visibility = "hidden";
document.getElementById(vPaNom + "bu" + i).className = "paBoto";
}
}
return false; // evitem la recàrrega de la pàgina
}
$(InitializationBoxElement);