簡體   English   中英

jQuery在Eclipse Neon中不起作用

[英]Jquery is not working in Eclipse Neon

我在lib文件夾中有jquery-1.9.1.jar文件,但是當我使用這樣的源代碼時

<script src="WebContent/WEB-INF/lib/jquery-1.9.1.jar" type="text/javascript"></script>

<script>
$( "button" ).click(function() {
  $( "p" ).toggle();
});
</script>
<button>Toggle</button>
<p>Hello</p>
<p style="display: none">Good Bye</p>

上面的代碼不起作用,是否有任何jQuery文件丟失追加到Eclipse Neon

檔案結構:

<html>
<body>  
<button>Toggle</button>
<p>Hello</p>
<p style="display: none">Good Bye</p>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("button").click(function(){
             $("p").toggle();
        });
    });
    </script>


</body>
</html>

這是例子。 您可以使用“ googleapis”或“ CDN”導入jquery。

googleapis:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script>
$( "button" ).click(function() {
  $( "p" ).toggle();
});
</script>
<button>Toggle</button>
<p>Hello</p>
<p style="display: none">Good Bye</p>

CDN:

<script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script>
$( "button" ).click(function() {
  $( "p" ).toggle();
});
</script>
<button>Toggle</button>
<p>Hello</p>
<p style="display: none">Good Bye</p>

暫無
暫無

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

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