【问题标题】:I receive the following error ReferenceError: document is not defined when running my html code in Cloud 9我收到以下错误 ReferenceError: document is not defined when running my html code in Cloud 9
【发布时间】:2015-01-07 03:54:19
【问题描述】:

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

ReferenceError: 文档未定义

我通过以下方式在 html 文件中将 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>
    <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):

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

谁能告诉我哪里出错了?

【问题讨论】:

    标签: javascript jquery html referenceerror


    【解决方案1】:

    试试

    &lt;!doctype html&gt;

    What_is_the_DOCTYPE_for_modern_HTML_documents,Choosing_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>

    【讨论】:

    • 我很感激。我实际上是在发布这篇文章后大约 5 分钟才把它弄出来的。
    猜你喜欢
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 2020-03-01
    • 1970-01-01
    相关资源
    最近更新 更多