當(dāng)前位置:
首頁(yè) >
SpringBoot中使用thymeleaf时点击按钮触发事件失败
發(fā)布時(shí)間:2025/3/19
36
豆豆
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot中使用thymeleaf时点击按钮触发事件失败
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
場(chǎng)景
在SpringBoot項(xiàng)目中使用thymeleaf模板時(shí)按鈕的點(diǎn)擊事件沒法觸發(fā)。
需要用到j(luò)query的delegate()函數(shù)。
delegate()函數(shù)用于為指定元素的一個(gè)或多個(gè)事件綁定事件處理函數(shù)。
實(shí)現(xiàn)
html代碼:
<button id="uploladBtn" class="btn btn-info mt-2" type="button" ><i class="fa fa-reply"></i>上傳</button>引入js文件:
th:replace="layout/layout(title='收貨單數(shù)據(jù)',cssPaths='/public/css/plugins/jsTree/style.min.css',jsPaths='/modular/receiveOrder/wmsReceiveOrder.js')">js代碼:
$(document).delegate("button#uploladBtn", "click", function () {uploadExcel();});這樣就能在js文件中通過button的id觸發(fā)點(diǎn)擊事件。
總結(jié)
以上是生活随笔為你收集整理的SpringBoot中使用thymeleaf时点击按钮触发事件失败的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot中使用thymele
- 下一篇: Eclipse中实现SpringBoot