经过几个小时的极度愤怒、愤怒、震惊——也许只是单纯的怀疑——我在这里发生了什么事,我才来到这里。
我试图在冗长的脚本中创建最简单的函数——通过 Id 获取元素,然后根据变量更改类的一部分。听起来很容易对吧?以下是相关代码:
{literal}
// check to see what kind of ban is this based on the ban_until and ban_at columns in table banlist from return data of /inc/classes/bans.class.php
var banduration = {/literal}{$ban.until - $ban.at}{literal};
if (banduration !== 1 || 0) {
var bantype = ((banduration < 0 || banduration > 3600) ? "ban" : "warning");
}
// replace all classnames with others in case this is a warning/ban, and END the script before it also changes modnames
if (bantype === "warning" || "ban") {
document.getElementbyId("modname_message_background").className = "common_background " + bantype + "_background";
document.getElementById("modname_message_bottomribbon").className = "common_bottomribbon " + bantype + "_bottomribbon";
document.getElementById("modname_message_letterbox").className = "common_letterbox " + bantype + "_letterbox";
document.getElementById("modname_message_modname").className = "common_modname " + bantype + "_modname";
document.getElementById("modname_message_servertime").className = "common_servertime " + bantype + "_servertime";
document.getElementById("modname_message_signature").className = "common_signature " + bantype + "_signature";
document.getElementById("modname_message_topribbon").className = "common_topribbon " + bantype + "_topribbon";
document.getElementById("modname_message_username").className = "common_username " + bantype + "_username";
}
这是相当不言自明的:这是在 Smarty 模板中,$ban.until
是禁令结束$ban.at
的 unix 时间,也是应用它的 unix 时间,等等。但是当我运行这个脚本时,该脚本旨在根据各个版主等级(稍后但我离题)和消息类型(消息、警告或禁令)来更改禁令消息。当我插入这个时,只使用了第一行。激动,我花了两个小时以不同的方式多次修改它,但完全无济于事。我对自己很生气,我写了这个:
if (bantype == "warning" || "ban") {
var list = ["modname_message_background","modname_message_bottomribbon","modname_message_letterbox","modname_message_modname","modname_message_servertime","modname_message_signature","modname_message_topribbon","modname_message_username"];
var secondlist = ["background","bottomribbon","letterbox","modname","servertime","signature","topribbon","username"];
for (var i=0;i<list.length;i++) {
document.getElementById(list[i]).className = "common_" + secondlist[i] + " " + bantype + "_" + secondlist[i];
}
}
return;
这也不起作用。我难以置信——被打败了,我来到这里,为我不得不错过的荒谬简单的错误辩护,因为只有如此简单的事情才会如此令人讨厌。
我可以确认变量banduration
工作正常(使用alert
)。