jQuery document.ready not firing (have included jq)



所以,在遍历了google和stackoverflow一小段时间之后,我发现的大多数资源都是错误地包含jQuery的人,我正确地包含了jQuery。

我的标题中有这个:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <?php wp_head(); ?>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title>
  <?php bloginfo('name'); ?>
</title>
<link href="<?php echo home_url(); ?>/css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {   
  alert("Hey");
  });
}
  alert("hello");

还有我需要的其他一切。当我准备好文档时,它会提醒您好,但是当文档准备就绪时,它也不会发出警报。我以前从未遇到过jQuery的问题。

任何帮助将不胜感激。

您有一个语法错误:)试试这个!

$(document).ready(function() {   
  alert("Hey");
});

在您的代码中看到了一个额外的大括号。 尝试:

$(document).ready(function() {   
  alert("Hey");
  });
//} Remove this brace

您的警报("嘿")正下方有一个额外的括号,导致错误。取下那个支架,你应该很高兴。

第二个<script type="text/javascript">更改为<script>

$(document).ready(function()替换为$(function ()

取出多余的}

$(document).ready(function() {   
    //code  goes here
    alert("Hey");
});

它将起作用,因此您应该将代码放在就绪函数中。

相关内容

最新更新