全局计数变量不增加

由于某种原因,我无法让全局变量计数器增加,即使它在发生 count++ 的函数内增加也是如此。我的输出结果在函数内输出的文本和函数外部的文本之间是不同的。知道我在这里做错了什么吗?Survey.oncomplete 函数结果的每次迭代计数不应该增加吗?

Survey

    .StylesManager

    .applyTheme("modern");


var kn2 = "LwrHXqFRN_pszCopTKHF_Q"

var kn3 = "exroCUoYl4wVzs7pKU_49w"


var count = 0


var keyname = ("kn" + count)


var mapilink = "https://images.mapillary.com/" + (keyname) + "/thumb-1024.jpg";


var json = {

 pages: [

  {

   name: "page1",

   elements: [

    {

     type: "image",

     name: "image",

     imageLink: (mapilink),

     imageHeight: 580,

     imageWidth: 640

    },

    {

     type: "html",

     name: (keyname),

     visible: false,

     html: (keyname)

    },

    {

     type: "rating",

     name: "Walkability",

     title: "How walkable does this look to you"

    },

    {

     type: "rating",

     name: "Saftey",

     title: "How safe does this look to you"

    },

    {

     type: "rating",

     name: "Comfortability",

     title: "How comfortable does this look to you"

    }

   ]

  }

 ]

}


window.survey = new Survey.Model(json);


var username = document.getElementById("user").value;


survey

    .onComplete

    .add(function (result) {

        count ++;

        var PID = document.getElementById("user").value;

        var results = PID + "_" + (keyname) + ":\n" + JSON.stringify(result.data, null, 3) + (count) ;

        document

            .querySelector('#surveyResult')

            .textContent = results;

    survey.clear();

    survey.render();

    });


$("#surveyElement").Survey({model: survey});


慕尼黑8549860
浏览 88回答 1
1回答

Cats萌萌

 基本上,需要将所有内容包装在更多函数中。函数输出函数文本而不是预期输出
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript