Thymeleaf onclick 将 td 值发送到 javascript 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32994746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Thymeleaf onclick send td value to javascript function
提问by Gururaj Mb
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.
但我没有得到实际价值。
回答by Gururaj Mb
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);
}
回答by Prabhat
For passing multiple parameters, you can use the following:
要传递多个参数,您可以使用以下内容:
th:onclick="'doSomething(\''+${val1}+ '\',\''+${val2}+'\',\''+${val3}+'\');'"
回答by coms
Cleaner with literal substitution ||:
带有字面替换的清洁器 ||:
th:onclick="|getPropId('${properties.id}');|"
Multiple case:
多种情况:
th:onclick="|getPropId('${var1}','${var2}');|"
回答by Ashish
i solved the same problemm by declaring th:attribute
我通过声明 th:attribute 解决了同样的问题
<div class="row" th:each="data,i : ${obj}">
<a href="javascript:void(0);" th:attr="onclick='loadDetails(\'' + ${data.objId}+'\')'">
</a>
</div>