繁体   English   中英

Javascript代码在Windows的Visual Studio Express 2013预览中不起作用

[英]Javascript code not working in Visual Studio Express 2013 Preview for Windows

因此,这是我的第一个Windows 8应用程序,我正在使用html / css和JS进行开发,我最初是在浏览器上开发的(我知道,不是一个好习惯),我想在Windows 8.1应用程序一切似乎都有轻微的毛刺,我可以轻松修复,但是javascript代码根本无法正常工作,即使它在浏览器中也能正常工作。

简而言之:该应用程序使您可以从1h倒计时,或从1000万向下倒计时(出于某种目的),每次倒计时都有两个停顿时间:一个开始按钮和一个停止按钮。

我不知道为什么,控制台显示以下错误: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();
})();

看来您正在使用jQuery。 确保您正在使用jQuery 2.0并从您的应用程序包中本地提供它。

您看到的特定错误很可能是使用innerHTML设置倒数计时器的结果。 由于应用程序以提升的特权(可能访问用户文件等)运行,因此您的代码不得执行可能引入漏洞的事情。 innerHTML可用于动态加载脚本,因此不鼓励使用它。

在您的应用程序中,看起来您可以轻松地使用innerText代替。 如果必须使用innerHTML,请尝试使用toStaticHTML( )或将其包装在MSApp.execUnsafeLocalFunction() 您可以阅读有关开发安全应用程序的更多信息。

不要再使用VS2013预览版了。 RTM已经退出。 在此处获取最终版本:

http://www.microsoft.com/visualstudio/chi/downloads#d-2013-express

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM