经过数小时的愤怒,愤怒,震惊-也许仅仅是出于怀疑,我才来到这里,这是发生在我身上的一切。
我试图在冗长的脚本中创建最简单的函数-通过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
是被实施禁令的统一时间,依此类推。但是,当我运行此脚本时,该脚本旨在根据各个主持人级别(后来我离题)和消息类型(消息,警告或禁止)来更改禁止消息。当我插入此代码时,仅使用第一行。我激动不安,花了两个小时以不同的方式对其进行了多次重做,但完全没有用。我对自己大为恼火,写道: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
)。 最佳答案
if (bantype === "warning" || "ban")
不按照您的想法去做。等效于:
if ((bantype === "warning") || "ban")
这总是正确的,因为
"ban"
不是错误的。它应该是:if (bantype === "warning" || bantype === "ban")
和:
if (banduration !== 1 || 0)
应该:
if (banduration !== 1 && banduration !== 0)