0

だから、これは私の最初の Windows 8 アプリで、html/css と JS を使用して取り組んでいます。最初はブラウザーで開発しました (私は知っていますが、良い習慣ではありません)。 Windows 8.1 アプリ すべてにわずかな問題があるようで、簡単に修正できましたが、ブラウザでは完全に機能したにもかかわらず、javascript コードはまったく機能しませんでした。

短編小説: このアプリでは、1 時間または 10 分ダウン (何らかの目的で) からカウントダウンを作成できます。各カウントダウンには、開始ボタンと停止ボタンの 2 つのボタンがあります。

理由はわかりませんが、コンソールに次のエラーが表示されます: HTML1701

コードは次のとおりです。

(function () {
"use strict";

var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;

app.onactivated = function (args) {
    if (args.detail.kind === activation.ActivationKind.launch) {
        if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
            // TODO: This application has been newly launched. Initialize
            // your application here.
        } else {
            // TODO: This application has been reactivated from suspension.
            // Restore application state here.
        }
        args.setPromise(WinJS.UI.processAll());
    }
};

app.oncheckpoint = function (args) {
    // TODO: This application is about to be suspended. Save any state
    // that needs to persist across suspensions here. You might use the
    // WinJS.Application.sessionState object, which is automatically
    // saved and restored across suspension. If you need to complete an
    // asynchronous operation before your application is suspended, call
    // args.setPromise().

    $(document).ready(function () {
        var h, m, s, h1, m1, s1, output, output1, inter, inter1;

        //Preparing all the functions

        //facts' animation function

        function facts() {
            function solve() {
                setTimeout(function () {
                    $("#fun1").animate({ opacity: "0", }, 500, function () {
                        $("#fun2").animate({ opacity: "1" }, 500);
                    });
                }, 10500);
                setTimeout(function () {
                    $("#fun2").animate({ opacity: "0", }, 500, function () {
                        $("#fun3").animate({ opacity: "1" }, 500);
                    });
                }, 21500);
                setTimeout(function () {
                    $("#fun3").animate({ opacity: "0", }, 500, function () {
                        $("#fun4").animate({ opacity: "1" }, 500);
                    });
                }, 31500);
                setTimeout(function () {
                    $("#fun4").animate({ opacity: "0", }, 500, function () {
                        $("#fun1").animate({ opacity: "1" }, 500);
                    });
                }, 41500);
            }
            solve();
            setInterval(function () { solve(); }, 41520);

            //Work Counting functions

        }

        function startWork() {
            h = 1;
            m = 0;
            s = 0;
            document.getElementById("WTM").innerHTML = "01:00:00"
            inter = setInterval(function () { countWork() }, 1000);
        }

        function countWork() {
            if (s == 0 && m == 0 && h == 0) {
                $("#StartW").animate({ opacity: 1, }, 500);
                clearInterval(inter);
            }
            else if (s == 0 && m == 0 && h != 0) {
                h = h - 1;
                m = 59;
                s = 59;
            }
            else if (s == 0 && m != 0) {
                m = m - 1;
                s = 59;
            }
            else if (s != 0)
            { s = s - 1; }
            if (typeof (s) != "string" && s < 10)
            { s = "0" + s; }
            if (typeof (m) != "string" && m < 10)
            { m = "0" + m; }
            if (typeof (h) != "string" && h < 10)
            { h = "0" + h; }
            output = h + ":" + m + ":" + s;
            document.getElementById("WTM").innerHTML = output;
        }

        //Rest Counting functions

        function startRest() {
            h1 = 0;
            m1 = 10;
            s1 = 0;
            document.getElementById("RTM").innerHTML = "00:10:00";
            inter1 = setInterval(function () { countRest() }, 1000);
        }

        function countRest() {
            if (s1 == 0 && m1 == 0 && h1 == 0) {
                $("#StartR").animate({ opacity: 1, }, 500);
                clearInterval(inter1);
            }
            else if (s1 == 0 && m1 == 0 && h1 != 0) {
                h1 = h1 - 1;
                m1 = 59;
                s1 = 59;
            }
            else if (s1 == 0 && m1 != 0) {
                m1 = m1 - 1;
                s1 = 59;
            }
            else if (s1 != 0)
            { s1 = s1 - 1; }

            if (typeof (s1) != "string" && s1 < 10)
            { s1 = "0" + s1; }
            if (typeof (m1) != "string" && m1 < 10)
            { m1 = "0" + m1; }
            if (typeof (h1) != "string" && h1 < 10)
            { h1 = "0" + h1; }
            output1 = h1 + ":" + m1 + ":" + s1;
            document.getElementById("RTM").innerHTML = output1;
        }

        //Calling the needed functions

        $("#StopW").click(function () {
            clearInterval(inter);
            document.getElementById("WTM").innerHTML = "00:00:00";
            $("#StartW").animate({ opacity: 1, }, 500);
        });

        $("#StartW").click(function () {
            startWork();
            $("#StartW").animate({ opacity: 0, }, 2000);
        });


        $("#StopR").click(function () {
            clearInterval(inter1);
            document.getElementById("RTM").innerHTML = "00:00:00";
            $("#StartR").animate({ opacity: 1, }, 500);

        });

        $("#StartR").click(function () {
            startRest();
            $("#StartR").animate({ opacity: 0, }, 2000);
        });

        facts();

    });
};

app.start();
})();
4

2 に答える 2

0

jQueryを使用しているようです。jQuery 2.0を使用していて、アプリ パッケージからローカルで提供していることを確認してください。

表示されている特定のエラーは、 を使用innerHTMLしてカウントダウン タイマーを設定した結果である可能性があります。アプリは昇格された特権 (ユーザー ファイルへの潜在的なアクセスなど) で実行されるため、脆弱性を引き起こす可能性のあることをコードで実行してはなりません。innerHTMLスクリプトを動的にロードするために使用できるため、使用しないことをお勧めします。

innerTextあなたのアプリケーションでは、代わりに簡単に使用できるようです。innerHTML を使用する必要がある場合は、toStaticHTML() を使用するか、 でラップしてみてくださいMSApp.execUnsafeLocalFunction()安全なアプリの開発について詳しく読むことができます。

于 2013-11-03T17:00:31.100 に答える