0

私は、ここで私に起こったことに対する、数時間の際立った怒り、怒り、ショック - おそらく単なる不信感 - の後にここに来ています。

長いスクリプトで最も単純な関数を作成しようとしました。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 時間です。しかし、このスクリプトを実行すると、個々のモデレーターのランク (後で脱線します) とメッセージの種類 (メッセージ、警告、または禁止) に応じて禁止メッセージを変更するように設計されています。これを挿入すると、最初の行だけが使用されました。動揺して、私は2時間かけてさまざまな方法で何度も作り直しましたが、まったく役に立ちませんでした. 自分自身に激怒して、私はこれを書きました:

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)。

4

1 に答える 1

2
if (bantype === "warning" || "ban")

あなたが思っていることをしません。それは以下と同等です:

if ((bantype === "warning") || "ban")

は偽ではないため、これは常に真です"ban"。そのはず:

if (bantype === "warning" || bantype === "ban")

と:

if (banduration !== 1 || 0)

次のようにする必要があります。

if (banduration !== 1 && banduration !== 0)
于 2013-03-02T11:33:48.960 に答える