在几个小时的愤怒,愤怒,震惊之后,我来到这里 - 也许只是简单的怀疑 - 在我身上发生的事情。
我试图在冗长的脚本中创建最简单的函数 - 通过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
是禁止结束的unix时间,$ban.at
是应用它的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
)。
答案 0 :(得分:2)
if (bantype === "warning" || "ban")
不符合您的想法。它相当于:
if ((bantype === "warning") || "ban")
总是如此,因为"ban"
不是假的。它应该是:
if (bantype === "warning" || bantype === "ban")
和
if (banduration !== 1 || 0)
应该是:
if (banduration !== 1 && banduration !== 0)