gpt4 book ai didi

javascript - JS 文件在一个页面上加载,但在另一个页面上不加载

转载 作者:行者123 更新时间:2023-12-03 03:13:07 25 4
gpt4 key购买 nike

我的 .js 文件加载一个页面,但不加载另一个页面。我已经点击了页面上的 JS 文件,但它不起作用,而且它似乎加载正常。

这不起作用

<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=yes">
<title>Homepage</title>
<link href="{% static "css/app_search.css" %}" rel="stylesheet"></link>
<!-- CSS reference: https://bootswatch.com/yeti/ -->
</head>

<body>

<!-- The header -->
<div class="container">
<div class="page-header" id="banner">
<div class="row">
<div class="col-lg-8 col-md-7 col-sm-6">
<h1>Home page/h1>
</div>
<a href="{% url 'app_new:new' %}">Submit a Collection Request</a>
</div>
</div>
</div>
<br>

<!-- The form -->
BLAH BLAH (TOOK OUT CODE TO SHORTEN)

<gcse:searchbox-only></gcse:searchbox-only>
</div>
<script src="{% static "js/scripts.js" %}"></script>
</body>

</html>

同时,这有效:

<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=yes">
<title>Seek</title>
<link href="{% static "css/app_search.css" %}" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- CSS reference: https://bootswatch.com/yeti/ -->
</head>

<body>

!~form BLAH BLAH TOOK OUT CODE TO SHORTEN

<script src="{% static "js/scripts.js" %}"></script>
</body>

</html>

这是JS文件...

$(document).ready(function(){
$(":submit").click(function(){
alert("Thank you for submitting a website request!");
});

!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="4.0.0";
analytics.load("key");
analytics.page();
}}();

(function() {
var cx = 'took out';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();

});

这很奇怪,因为如果 JS 错误,那么两个页面都不应该工作。我没有收到任何文件未找到错误等。

最佳答案

您正在使用jQuery,但没有导入它。导入 jQuery 脚本,如工作页面所示。​​

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

关于javascript - JS 文件在一个页面上加载,但在另一个页面上不加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46882271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com