簡體   English   中英

為什么我收到“未定義塊”錯誤?

[英]Why am I getting this error “block is not defined”?

我收到此JavaScript錯誤:“未定義塊”

<script type="text/javascript">
$(document).ready(function()
{
  $(".register_now").click(function()
  {

    $(".fp_top_right_login").slideToggle(600);
    var st = document.getElementById("fp_top_right_register").style.display;
    if(st == "" || st == "none")
    {
      window.setTimeout(document.getElementById("fp_top_right_register").style.display="block",600); //error happens here
    }
    else
    {
      window.setTimeout(document.getElementById("fp_top_right_register").style.display="none",600); //and also here
    }
  });
});
</script>

setTimeout將函數作為參數。 您可以使用匿名函數。 例:

window.setTimeout(function() {
    document.getElementById("fp_top_right_register").style.display="block"; 
}, 600);

您使用setTimeout的方式存在錯誤。

window.setTimeout(function(){document.getElementById("fp_top_right_register").style.display="block"},600);

另外,考慮使用jquery css

$('#fp_top_right_register').css('display','block');

window.setTimeout的第一個參數應該是一個函數,而不是字符串,這是分配的結果。

您可能想將該任務包裝在

function () { .... }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM