jQuery fadeOut不工作?

时间:2014-01-25 21:58:00

标签: javascript jquery html fadeout

好吧,我有以下HTML代码,适用于应该从API检索天气数据的应用程序。

<!DOCTYPE html>
<html>
  <head>
    <title>FastCast</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/footer.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
    <link rel="shortcut icon" href="favicon1.ico"/>
  </head>
  <body>
    <center>
    <h1><b>Welcome to FastCast!</b></h1>
    <div>
    <p><font size="3">FastCast is a web application designed to gather weather information from various sources and display it in an easy-to-read format.</font></p>
    <hr></hr>
    <div id-"all">
    <div id="picDiv">
    <img id="imgDisp" src="logo.jpg">
    </div>
    <p><font size="6">Enter you location to get started.</font></p>
    </div> 
    <form class="form-inline" role="form">
    <div class="form-group">
    <input type="text" class="form-control" id="Location" placeholder="ex. Boston, MA">
    </div>
    </form>
    <p><i>Press enter to continue.</i></p>
    <script>
    window.onkeydown = function(event) {
        if (event.keyCode === 13) {
            var x = document.getElementById("Location").value;
            var last2 = x.slice(-2);
            alert(last2);
            $(document).ready(function() {

                $('#all').fadeOut(1000);

            });
        }
    }
    </script>
    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://code.jquery.com/jquery.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    </center>
    </body>
    <div class="footer" id="footer">Developed in Twitter Bootstrap | Information from openweathermap.org | Tyler Jablonski, 2014+</div>
</html>

现在,我仍然在设置界面。在代码的末尾,我有一些Javascript,当用户按下回车键时,它会在文本框中提醒最后两个字符。这工作正常。但是,之后我还有一些jQuery,它应该会淡化掉所有内容。这部分不起作用。我得到警报,但没有消失。这是为什么?

您可以在此处查看此页面:https://googledrive.com/host/0B7jcQuOYGlvqOHBHN3VTTi11YUU/html.html

感谢。

1 个答案:

答案 0 :(得分:3)

你放div id-"all"而不是div id="all",所以jQuery无法定位该div