简体   繁体   English

我无法加载JavaScript

[英]I cannot load javascript

We've been doing my little mail project and I've encountered some problems. 我们一直在做我的小邮件项目,但遇到了一些问题。

I've been using tomcat and apache so I use jsp right now. 我一直在使用tomcat和apache,所以现在使用jsp。

My problem is that I cannot load js file with tag in jsp file. 我的问题是我无法在jsp文件中加载带有标签的js文件。 We want to make kind of single page application so some jsp files are calling other jsp files. 我们想要制作一种单页应用程序,因此某些jsp文件正在调用其他jsp文件。

Our jsp file structure is constructed like this way. 我们的jsp文件结构是按照这种方式构造的。

box.jsp -> mail-list.jsp -> (select mail from mail list, get mail content to communicate with server, append at the bottom of the list and swipe it with animation to show mail contents) -> detail-mail.jsp box.jsp-> mail-list.jsp->(从邮件列表中选择邮件,获取邮件内容以与服务器通信,追加到列表底部,然后用动画轻扫以显示邮件内容)->详细邮件。 JSP

In box.jsp, tags are working so I can load java scripts and use it because box.jsp(mail list viewer) shows mail list and all of our java script files are loaded at box.jsp. 在box.jsp中,标签可以正常工作,因此我可以加载Java脚本并使用它,因为box.jsp(邮件列表查看器)显示了邮件列表,而我们所有的Java脚本文件均已加载到box.jsp中。

But in detail-mail.jsp(show detail mail contents and etc), It doesn't work even though 'detail-mail.jsp' has tags. 但是在detail-mail.jsp(显示详细的邮件内容等)中,即使'detail-mail.jsp'具有标签,它也不起作用。

Even though css files are loaded, java script files aren't. 即使加载了CSS文件,也没有加载Java脚本文件。

Is there any way I can load java script file in this situation? 在这种情况下,有什么办法可以加载Java脚本文件?

If I understand correctly: Are you trying to load script tags in an e-mail? 如果我正确理解:您是否要在电子邮件中加载脚本标签?

I'm not familiar with JSP, but I have done a fair bit of e-mail development. 我对JSP不熟悉,但是我做了相当多的电子邮件开发。

You cannot use JavaScript in e-mails, unfortunately. 不幸的是,您不能在电子邮件中使用JavaScript。 So maybe the <script> tags are being removed from the output of detail-mail.jsp ? 因此,也许<script>标记已从detail-mail.jsp的输出中删除了?

You should use these code if you want to load javascripts dynamically with append child. 如果您要使用append child动态加载javascript,则应使用这些代码。

    const s = document.createElement('script');
    s.type = 'text/javascript';
    s.src = '/js/detail-mail.js';
    $('head').append(s);

If you load html after javascripts, javascripts cannot figure out DOM ELEMENTS. 如果您在javascript之后加载html,则javascript无法找出DOM ELEMENTS。 So you should load HTML and after that, you shoudl load javascripts. 因此,您应该加载HTML,然后再加载javascript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM