第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在加載 .json 文件數據后組合 if 語句運行時出現問題

在加載 .json 文件數據后組合 if 語句運行時出現問題

慕運維8079593 2022-10-08 15:40:26
我的頁面從 .json 文件加載數據并將其顯示在 html 頁面中。還有一個 location.reload 元素不斷查找更改的數據并在 .json 文件已更改時更新它。參見代碼屏幕 1var previous = null;var current = null;setInterval(function() {    $.getJSON('thenumber.json', function(data) {        var text = `The number = ${data.thenumber}<br>                     Confirmed = : ${data.confirmed}`        var pass = `${data.thenumber}`        var conf = `${data.confirmed}`        $(".mypanel").html(text);        $(".passRef").html(pass);        $(".confirmRef").html(conf);        current = JSON.stringify();                    if (previous && current && previous !== current) {            console.log('refresh');            location.reload();        }        previous = current;    });                       }, 2000);我還想添加一些 if 語句,這些語句只能在 .json 數據填充到 html 頁面后運行,我開始工作(不包括重新加載功能)代碼屏幕 2 之類的東西(由于某種原因它今晚不工作,嘆!)。  $(document).ready(() => {  function whatever() {  var what = document.getElementById('confirmRef').innerHTML;  if (what == 'true' ) {       console.log ("call button should activate");  } else if (what == 'false' ) {        console.log ("false confirmation");  } else {        console.log ("confirm says something else!");  }    $.getJSON('thenumber.json', function(data) {            var text = `The number = ${data.thenumber}<br>                         Confirmed = : ${data.confirmed}`            var pass = `${data.thenumber}`            var conf = `${data.confirmed}`            $(".mypanel").html(text);            $(".passRef").html(pass);            $(".confirmRef").html(conf);       })    .then(() => whatever());  };  });問題是,當我嘗試組合所有 3 個元素(代碼屏幕 3)時,我在某處搞砸了,如果能幫助我向我展示代碼應該如何解決問題的示例代碼,我將不勝感激。var previous = null;var current = null;$(document).ready(() => {  function whatever() {  var what = document.getElementById('confirmRef').innerHTML;        //console.log (what);
查看完整描述

1 回答

?
明月笑刀無情

TA貢獻1828條經驗 獲得超4個贊

在您的上一個代碼中,您將whatever()函數包裝在代碼周圍,并且您then是setInterval 嘗試這個的一部分


var previous = null;

var current = null;



$(document).ready(() => {

  function whatever() {


  var what = document.getElementById('confirmRef').innerHTML;


        //console.log (what);


if (what == 'true' ) {


       console.log ("call button should activate");


       //console.log (what);


} else if (what == 'false' ) {


        console.log ("false confirmation");


} else {


        console.log ("confirm says something else!");


  }

}

  setInterval(function() {

        $.getJSON('thenumber.json', function(data) {


            var text = `The number = ${data.thenumber}<br>

                         Confirmed = : ${data.confirmed}`


            var pass = `${data.thenumber}`


            var conf = `${data.confirmed}`



            $(".mypanel").html(text);


            $(".passRef").html(pass);


            $(".confirmRef").html(conf);



            current = JSON.stringify();            

            if (previous && current && previous !== current) {

                console.log('refresh');

                location.reload();

            }

            previous = current;

        })       

        .then(() => whatever());


    }, 2000);

});



查看完整回答
反對 回復 2022-10-08
  • 1 回答
  • 0 關注
  • 121 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號