简体   繁体   中英

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

I am getting this javascript error: "block is not defined"

<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 takes a function as a parameter. You can use an anonymous function. Example:

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

There is an error in you way of using setTimeout.

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

Also, consider using jquery css :

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

The first argument to window.setTimeout should be a function, not a string, which is the result of your assignment.

You probably wanted to wrap that assignment in

function () { .... }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM