3

我发誓我之前在我的页面上包含了 jQuery 一百万次,但由于某种原因这不起作用。就好像什么都没有发生一样。

我已经包含了一个指向 jQuery.com 托管版本的外部链接。

有什么见解吗?

<html>
<head>
    <meta charset="utf-8" />


    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js" />
    <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js" />
    <script>

    $(function() {
    $( "#draggable3" ).draggable({ containment: "#containment-wrapper", scroll: false });


    $("input[type=submit], a, button")
        .button()
        .click(function( event )
        {
            event.preventDefault();
            $("#infobar").append('<p>Full name = ' + $("#first").val() + ' ' +  $("#last").val() + '  </p>');  
            alert("Name added!");                 
        });

       $.getJSON('friends.json', function(data)
       {
            $.each(data, function()
            {
                $.each(this, function(k, v)
                {
                  $("#infobar").append('<p>' + v.firstName + ' '  + v.lastName + '</p>');
               });

            });     

       });
});
    </script>

    <style>
    .draggable { width: 50px; height: 50px; padding: 0.5em; float: left; margin: 0 10px 10px 0; }
#draggable, #draggable2 { margin-bottom:20px; }
#draggable { cursor: n-resize; }
#draggable2 { cursor: e-resize; }
#containment-wrapper { width: 95%; height:150px; border:2px solid #D00000 ; padding: 10px; border-style:dashed;}
#infobar {background: #E8E8E8; width:100%}
</style>

</head>
<body>


<div id="containment-wrapper">
    First Name: <input type="text" name="firstname" id="first"><br>
    Last name: <input type="text" name="lastname" id="last">
    <input type="submit" value="Calclulate" />

    <div id="draggable3" class="draggable ui-widget-content">
        <p>LET ME OUT!</p>
</div>


</div>
<div id="infobar">

  </div>



</body>
</html>​​​​​​​​​
4

2 回答 2

4

<script> is not self-closing

<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
于 2012-11-14T19:21:47.680 回答
3

<script> elements require an end tag. You should write:

<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>

Instead of:

<script src="http://code.jquery.com/jquery-1.8.2.js" />
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js" />

Also keep in mind the type attribute must be specified in HTML4 (it defaults to text/javascript in HTML5). You might want to specify it explicitly, depending on your document type.

于 2012-11-14T19:21:30.067 回答