简体   繁体   中英

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:

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.

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

Now if its displying proper properties.id in javascript function.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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