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)函數中

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