天天看點

springboot thymeleaf 對自定義标簽指派

在開發中遇到需要對自定義屬性進行指派,之前項目的寫法為:<a href="javascript:void(0);" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow"   th:data-uri="${s.resUrl}"></a>,結果在新項目中js 通過data_uri = $(this).attr('data-uri')擷取到的值為undefined,網上看了幾篇博文(比較詳細的一篇部落格https://blog.csdn.net/nihaoqiulinhe/article/details/80984875,感謝部落客的分享)發現應使用th:attr對屬性進行自定義指派

<a href="javascript:void(0);" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" th:attr="data-uri=${s.resUrl},data-id=${indexP.index+''+indexS.index}" ></a>

當有多個自定義屬性時要用逗号進行分割 而不是用多個th:attr