外部加载的javascript获胜't执行

externally loaded javascript won't execute

本文关键字:执行 获胜 加载 javascript 外部      更新时间:2023-09-26

我在从外部文件运行javascript时遇到问题。以下是它包含在html:中的位置

<div id="article-author-list" class="article-author-list">
    <#list authorGroups as authorGroupItem>
        <@authorGroup item=authorGroupItem/>
    </#list>
    <script type="text/javascript">alert('Hello??');</script>
    <script type="text/javascript" src="/js/article/truncateAuthors.js">    </script>
</div>

而这里是truncateAuthors.js:

alert('Found the script!!!');
$(window).load(function () {
    alert('Found the script.');
});
$(document).ready(function () {
    alert('Document is ready');
});
$(function(){
    alert('Running the script');
});

加载html时,唯一的警报是"你好??"来自内联脚本。如何获取要执行的外部文件?

在调用javascript之前,请添加以下内容<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>对于您的文件,它将正常工作。这是我们在jquery 中编写代码时必须使用的jquery库文件

我找到了!该项目使用requireJS,我需要将其添加到声明中。感谢您的回答:)