jQuery在单独的文件中不起作用,但是当我将其放在html文件的正文中时起作用吗? [英] jquery does not work in seperate file but works when I put it in the body of my html file?

查看:73
本文介绍了jQuery在单独的文件中不起作用,但是当我将其放在html文件的正文中时起作用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将jQuery代码放在我的php文件的主体中时,它可以工作,但是当我将其放在单独的文件中并进行链接时,它不起作用?有什么想法吗?

When I put jquery code in the body of my php file it works, however when I put it in a seperate file and link it then it doesnt work? any ideas?

       <!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script src="script.js"></script>
  </head>


  <body>

    <p>hello</p>

  </body>
</html>

这是我的JavaScript文件.

and here is my javascript file.

$(document).ready(function(){

  $("p").click(function(){
    $("p").hide();
  });
});

推荐答案

我只能假设您的问题是您正在本地计算机上进行开发并从硬盘驱动器加载HTML.

I can only just assume that your issue is that you are developing on your local machine and loading your HTML from your harddrive.

该问题可能解决了您的问题;

This question likely addresses your question;

将本地javascript文件加载到chrome中进行测试吗?

您遇到的问题称为sandboxing,出于安全原因,这种方式就是这样.令人担心的是,IE实际上没有显示该问题.

What you are running into is called sandboxing and is that way for security reasons. It is concerning that IE does not display the issue actually.

This article has a good explanation of the need for your browser to be sandboxed.

这篇关于jQuery在单独的文件中不起作用,但是当我将其放在html文件的正文中时起作用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆