繁体   English   中英

jQuery无法在我的HTML页面上工作。 我没有按预期在页面的onLoad上收到警报

[英]jquery not working on my html page. I am not getting alert onLoad of the page as expected

我期望会弹出准备好警报的文档,由于某种奇怪的原因,这确实没有发生。 可能出什么问题了? jQuery库的位置在js目录中。 我在所有浏览器上尝试过,但无法正常工作。 顺便说一句,我对jQuery非常陌生,不知道如何使其工作。

<!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
        <script type="javascript" src="js/jquery-2.1.1.min.js">

            $(document).ready(function(){
                        alert("Doc Ready"); // I was expecting the alert to work which is not happening.
                    }
            );


        </script>

        <style type="text/css">

            #topbar {
                height: 40px;
                width: 98%;
                background-color: #062f9e;
                border-style: solid;
                border-width: 5px;
                border-color: goldenrod;
                text-align: center;
                font-family: fantasy;
                font-style: normal;
                font-size: 24px;
                color: darkkhaki;
                font-weight: bold;


            }

            #contentPane {
                margin-top : 50px;
                left: 0;
                right: 0;
                height: 100%;
                background-color: sandybrown;
                border-color: darkslategray;
                border: thick;


            }

            body {
                width: 100%;
                height: 100%;
                background-color: darkgrey;
            }

            .image{
                height: auto;
                width: auto;
                float: left;
                border-style: solid;
                border-color: ghostwhite;
                border-width: 10px;
            }

        </style>
    </head>
    <body>

        <div id="topbar">AGNI SHIKHA</div>
        <div id="contentPane">
            <img id="agnishikaImg" class="image" src="res/agnishikha.jpeg" alt="Agnishikha Image">

        </div>
        <div style="clear: both;"></div>

    </body>
    </html>

您需要将这些脚本分成两个不同的块:

<script src="js/jquery-2.1.1.min.js"></script>
<script>
$(document).ready(function () {
    alert("Doc Ready"); // I was expecting the alert to work which is not happening.
});
</script>

脚本需要分开。

<script type="javascript" src="js/jquery-2.1.1.min.js"></script>
<script>
    $(document).ready(function(){

       alert("Doc Ready"); // :)
    });
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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