简体   繁体   English

带有JS脚本的Thymeleaf onclick属性在Spring中不起作用

[英]Thymeleaf onclick attribute with JS script won't work in Spring

I have a table generated through: 我有一个通过生成的表:

<tr *some other th tags* th:onclick="'javascript:openPoolModal(\\''+ ${networkHashrate.id} + '\\');'">

I have a openPoolModal function in static/js/openPoolModal.js 我在static/js/openPoolModal.js有一个openPoolModal函数

I have added a <script type="text/javascript" src="../js/openPoolModal.js"></script> to the .html file header where the function is used. 我已经在使用该功能的.html文件头中添加了<script type="text/javascript" src="../js/openPoolModal.js"></script>

The function looks like this: 该函数如下所示:

function openPoolModal(id){

$.ajax({
    url: "/" + id,
    success: function(data){
    $("#PoolModalHolder").html(data);
    $("#PoolModal").modal("show");
    }
});
}

What am I missing? 我想念什么?

I think this is a directory problem. 我认为这是目录问题。 You're including the js file by calling this script from your html file: 您将通过从html文件中调用以下脚本来包含js文件:

<script type="text/javascript" src="../js/openPoolModal.js"></script>

But if your html file is in directory resources/templates/ then this script is trying to call resources/js/openPoolModel.js which isn't where your Javascript file is. 但是,如果您的html文件位于resources/templates/目录中,则此脚本将尝试调用resources/js/openPoolModel.js ,而不是Javascript文件所在的位置。

Adding the js function directly to the html file called the function so your script and directory is wrong. 将js函数直接添加到称为函数的html文件中,因此您的脚本和目录错误。

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

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