使用jquery隐藏nodeJs中的元素

时间:2022-12-02 17:46:17

I'm new to nodeJs and been playing around with it. I've also tried NodeJs express and it all seems fine. However I've been trying to use Jquery in such a manner that it can handle client side operations, like effects and the like but seem to fail with even the most basic things. So the code is as follows:

我是nodeJs的新手并且一直在玩它。我也尝试过NodeJs express,这一切看起来都很好。但是我一直试图以这样一种方式使用Jquery,它可以处理客户端操作,比如效果等,但即使是最基本的东西也似乎失败了。所以代码如下:

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="../public/javascripts/indexSite.js"></script>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css'/>
</head>
<body>
<h1><%= title %></h1>

<p>Welcome to <%= title %></p>
</body>
</html>

Which is just the index.ejs file that is created when creating a project in nodeJs express with the addition of two script tags. The indexSite.Js file is as follows:

这只是在nodeJs express中创建项目时创建的index.ejs文件,添加了两个脚本标记。 indexSite.Js文件如下:

$(document).ready(function(){
    $("body").hide();
});

Which is rather simple yet I fail to actually hide the body.. Also when checking the console the application,server what have you, pick up the indexsite.js file:

这是相当简单但我实际上无法隐藏身体..另外当检查控制台的应用程序,服务器有什么有你,拿起indexsite.js文件:

GET /public/javascripts/indexSite.js 404 5.113 ms - 856
GET /stylesheets/style.css 304 6.886 ms - -
GET / 304 1.753 ms - -

So I'm rather dumbfounded

所以我很傻眼

1 个解决方案

#1


2  

There is a 404 (Not found error) on indexSite.js.

indexSite.js上有404(未找到错误)。

Replace :

<script src="../public/javascripts/indexSite.js"></script>

With :

<script src="/javascripts/indexSite.js"></script>

#1


2  

There is a 404 (Not found error) on indexSite.js.

indexSite.js上有404(未找到错误)。

Replace :

<script src="../public/javascripts/indexSite.js"></script>

With :

<script src="/javascripts/indexSite.js"></script>