thymeleaf中如何给onclick事件传值

<span th:text="${naire.title}" th:onclick="|javascript:goqns('${naire.qnid}')|"></span>

其中,naire是后台储存在request域中的数据,goqns是js中自己写的点击事件的方法,这样就能能将qnid的值传入goqns函数中。这种方法在值为int类型的时是可行的,但是当要穿的值为其他类型就不行了。

传其他类型的值可以使用这种方法:

<td><button th:data-id="${user.username}" onclick="goUserinfo(this.getAttribute('data-id'))" type="button" class="btn btn-info">Details</button></td>

就可将值传入js中的goUserinfo(username)函数中

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章