簡體   English   中英

jQuery選擇器隱藏功能

[英]jQuery selector hide function

這是我的HTML文件的內容:

<!DOCTYPE html>
            <!-- The above DOCTYPE declaration tells the browser that this page conforms to HTML 5 standards -->
    <head>

        <meta http-equiv="author" content="Chris" />
        <link href="jquery.css" type="text/css" rel="stylesheet" />
</script>
    <script src="js/jquery-3.3.1.min.js">
</script>
<script>
    $(document).ready(function() {
        $('#message').hide();
    });
</script>
    </head>
    <body>
        <p id="message">Hello World!</p>
    </body>
</html>

我有一個名為jquery.js的文件,它是jQuery 3.3.1的縮小版,並且保存在HTML文件和CSS文件所在的js文件夾中。 在本文檔中,我試圖使用hide()函數隱藏帶有消息 ID的段落,但是當我在Google Chrome瀏覽器中打開文件時,該段落仍然存在。

注意:顯然,我是JavaScript和jQuery庫實現的新手。

好。 所以我弄清楚發生了什么。 我正在從一本書中學習JavaScript,這本書說在將它鏈接到JavaScript文件時,即使版本名和正確的文件名不正確,其版本號和“ min”擴展也都包含在HTML文件中。 由於我的jQuery庫是jquery.js,因此我只刪除了版本號和“ min”擴展名。 一旦執行完此操作,根據hide()函數,該段落就消失了。 謝謝大家的回應。 這只是本書和我的大腦之間無法交流的原因。

<!DOCTYPE html>
    <!-- The above DOCTYPE declaration tells the browser that this page conforms to HTML 5 standards -->
    <head>
        <meta http-equiv="author" content="Chris" />
        <link href="jquery.css" type="text/css" rel="stylesheet" />
  <script src="jquery.js"></script>
  <script>
  $(document).ready(function() {
    $('#message').hide();
    console.log($.fn.jquery);
  });
  </script>
</head>
<body>
  <p id="message">Hello World!</p>
</body>
</html>

幾個盲目的錯誤...假設您的jQuery庫已加載。

<!DOCTYPE html>
<!-- The above DOCTYPE declaration tells the browser that this page conforms to HTML 5 standards -->
<html> <!-- MISSING -->
<head>
  <meta http-equiv="author" content="Chris" />
  <link href="jquery.css" type="text/css" rel="stylesheet" />
  <!--/script--> <!-- WHAT? Commented out -->
  <script src="js/jquery-3.3.1.min.js"></script>
  <script>
  $(document).ready(function() {
    $('#message').hide();
  });
  </script>
</head>
<body>
  <p id="message">Hello World!</p>
</body>
</html>

缺少標簽和額外標簽。
告訴我是否可以解決奇怪的問題。

<!DOCTYPE html>
<html>
            <!-- The above DOCTYPE declaration tells the browser that this page conforms to HTML 5 standards -->
    <head>
        <meta http-equiv="author" content="Chris" />
        <link href="jquery.css" type="text/css" rel="stylesheet" />
    <script src="js/jquery-3.3.1.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#message').hide();
        });
    </script>
    </head>
    <body>
        <p id="message">Hello World!</p>
    </body>
</html>

如上所述修改HTML。 我刪除了多余的</script>並添加了缺少的<html>

問題是您有一個額外的</script>標記。 只需將其刪除。

 <html>
    <head>
       <meta http-equiv="author" content="Chris" />
       <link href="jquery.css" type="text/css" rel="stylesheet" />

       <script src="js/jquery-3.3.1.min.js"></script>
       <script>
           $(document).ready(function() {
               $('#message').hide();
           });
       </script>
   </head>
   <body>
      <p id="message">Hello World!</p>
   </body>
 </html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM