简体   繁体   English

Thymeleaf onclick将td值发送到javascript函数

[英]Thymeleaf onclick send td value to javascript function

I am using "Thymeleaf", I want to send the value to javascript, I am new to this, I am trying below code: 我正在使用“Thymeleaf”,我想将值发送到javascript,我是新手,我正在尝试下面的代码:

onclick="getPropId('${properties.id}')"

and function 和功能

getPropId(inputID){alert(inputId);}

But I am not getting actual value. 但我没有获得实际价值。

Above issue is resolved now, we need to use Thymeleaf specific syntax. 上面的问题现在解决了,我们需要使用Thymeleaf特定的语法。

th:onclick="'getPropId(\'' + ${properties.id} + '\');'"

Now if its displying proper properties.id in javascript function. 现在,如果它在javascript函数中显示正确的properties.id。

function getPropId(inputID){
    alert(inputID);
}                           

要传递多个参数,可以使用以下命令:

th:onclick="'doSomething(\''+${val1}+ '\',\''+${val2}+'\',\''+${val3}+'\');'"

Cleaner with literal substitution ||: 清洁文字替换||:

th:onclick="|getPropId('${properties.id}');|"

Multiple case: 多个案例:

th:onclick="|getPropId('${var1}','${var2}');|"

i solved the same problemm by declaring th:attribute 我通过声明:属性解决了同样的问题

<div class="row" th:each="data,i : ${obj}">
    <a href="javascript:void(0);" th:attr="onclick='loadDetails(\'' + ${data.objId}+'\')'">
</a>
</div>

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

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