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