【问题标题】:Reload on click function not working in javascript重新加载点击功能在javascript中不起作用
【发布时间】:2021-08-29 21:32:06
【问题描述】:

我的页面上有一个按钮需要在点击时重新加载,但它没有这样做。 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.

【问题讨论】:

    标签: javascript window.location


    【解决方案1】:

    我认为 CodePen 删除了该功能。

    使用history作为替代方法,

    参数0表示返回的步数。

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

    使用

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

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

    【讨论】:

      猜你喜欢
      • 2017-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多