单击功能无法在JavaScript中重新加载

时间:2019-07-09 18:21:42

标签: javascript window.location

我的页面上有一个按钮,需要在单击时重新加载,但没有这样做。 https://codepen.io/JammyPiece/full/dBZaMP

它也应该在“死亡屏幕”后单击以重新加载,该屏幕解释了该生物死亡时的年龄。我在点击,什么都没发生。

我已经阅读了w3学校的文档,并了解了重新加载屏幕的各种方法。我看不出它们和我所做的事情有什么区别。


var c;


function myClock() {
   c=0;
    myTimer = setInterval(startUp, 60000);
    }


$(resetBtn).click(function(){
       refreshPage();
        myClock();
        living();
      });

function refreshPage(){
    window.location.reload();
}
function deathScreen(){

$(start).hide();
modal.style.display = "block";
$(dead).text(c);
clearInterval(myTimer);
$(ageing).text(0);

}
  // When the user clicks on <span> (x), close the modal

span.onclick = function() {
modal.style.display = "none";
refreshPage();
}

  // When the user clicks anywhere outside of the modal, close it

   window.onclick = function(event) {
if (event.target == modal) {
   modal.style.display = "none";
refreshPage();
}
}

我要

Failed to load resource: the server responded with a status of 404 ()
pen.js:37 Uncaught (in promise) DOMException
pen.js:33 Uncaught TypeError: window.location.removedByCodePen is not a function
    at refreshPage (pen.js:33)
    at HTMLSpanElement.span.onclick (pen.js:241)
6pen.js:33 Uncaught TypeError: window.location.removedByCodePen is not a function
    at refreshPage (pen.js:33)
    at HTMLButtonElement.<anonymous> (pen.js:27)
    at HTMLButtonElement.dispatch (jquery-3.3.1.slim.min.js:2)
    at HTMLButtonElement.v.handle (jquery-3.3.1.slim.min.js:2)
dBZaMP:1 Refused to apply style from 'https://s.codepen.io/JammyPiece/fullpage/messaround.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

1 个答案:

答案 0 :(得分:0)

我认为CodePen删除了该功能。

使用alternative方法,

参数0表示要返回的步骤数。

function refreshPage(){
    history.go(0);
}

OR

使用

function refreshPage(){
    window.location.href = window.location.href;
}

这会将位置重置为相同位置。页面将刷新。