Unable to run Jquery from local folder

*爱你&永不变心* 提交于 2019-12-02 23:49:33

问题


Hi I am new to web development. I need to work with JQuery. Even I have tried one jquery successfully but only after copying file to my online ftp folder. I am totally failed to run it from my local folder. Please explain it, how can I test some new scripts without having an additional excercise of copying file to ftp folder. Thanks in advance!

The Script I used (infect just copied from www.w3schools.com still this script only runs from ftp folder and I am unable to run it from my local folder. You can see there is not any local or fixed path that should be available from one place but not from another. The script is as:

<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide();
  });
});
</script>
</head>

<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body>
</html>

Now is not it possible to run this code from a folder on my on hard drive?


回答1:


Include in your head tag:

<!-- jQuery -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>

Like:

<head>
  <!-- jQuery -->
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>



回答2:


Include head tag

<html>
<head>
      <!-- jQuery -->
      <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
</body>
</html>



回答3:


You can use like this.

<head>
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">/script>
</head>
<body>
<p></P><input type=button value="Click me" id="btn1"/>

  <script>

  $('#btn1').click(function()
  {
      $('p').html("Hello World!");
  });

  </script>
</body>


来源:https://stackoverflow.com/questions/15200796/unable-to-run-jquery-from-local-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!