我收到以下错误ReferenceError:在Cloud 9中运行我的html代码时未定义文档

时间:2015-01-07 03:54:19

标签: javascript jquery html referenceerror

运行我的javascript文件时收到以下错误:

ReferenceError:未定义文档

我以下列方式将jquery带入html文件中的项目:

<!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>
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/stylesheet.css">
    <script src = "http://code.jquery.com/jquery-2.1.1.js"></script>
    <script src="javascript/index.js" type="text/javascript"></script>

</head>
<body>

    <div class="indexHead">
        <div id="logoDiv">
            <p id="logo">Ada</p>
            <p id="compName">Consulting</p>
            <p id="parCompName">A Sorma Enterprises Company</p>
        </div>
    </div>

    <div class="blocks">
        <div id="redBlock">
            <p id="socialContent">Social Content Marketing</p>
        </div>
        <div id="yellowBlock">
            <p id="webAndAppDev">Website and Application Development</p>
        </div>
        <div id="blueBlock">
            <p id="biContent">Business Intelligence</p>
        </div>
    </div>

    <div class="indexFoot">

    </div>

</body>
</html>

使用以下javascript(jquery):

&#13;
&#13;
$(document).ready(function(){
    $('#redBlock').click(function(){
    alert('alert');
    });
});
&#13;
&#13;
&#13;

有人可以告诉我哪里出错了吗?

1 个答案:

答案 0 :(得分:1)

尝试

<!doctype html>

请参阅What_is_the_DOCTYPE_for_modern_HTML_documentsChoosing_the_right_doctype_for_your_HTML_documents

$(document).ready(function(){
    console.log(jQuery().jquery)
    $('#redBlock').click(function(){
    alert('alert');
    });
})
  
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery-2.1.1.js"></script>
</head>
<body>

    <div class="indexHead">
        <div id="logoDiv">
            <p id="logo">Ada</p>
            <p id="compName">Consulting</p>
            <p id="parCompName">A Sorma Enterprises Company</p>
        </div>
    </div>

    <div class="blocks">
        <div id="redBlock">
            <p id="socialContent">Social Content Marketing</p>
        </div>
        <div id="yellowBlock">
            <p id="webAndAppDev">Website and Application Development</p>
        </div>
        <div id="blueBlock">
            <p id="biContent">Business Intelligence</p>
        </div>
    </div>

    <div class="indexFoot">

    </div>

</body>
</html>