使用Jquery獲取Thymeleaf參數(shù)的三種方式小結(jié)
在使用Thymeleaf進行數(shù)據(jù)填充的時候,發(fā)現(xiàn)使用jquery原始方式獲取內(nèi)容參數(shù)發(fā)現(xiàn)拿不到數(shù)據(jù)。將百度后看到的解決方案整理下來,僅供參考。
方法一:內(nèi)聯(lián)獲取
<script>標簽中 th:inline 一定不能少,通常在取值的前后會加上不同的注釋,不過個人覺得這樣子寫太麻煩了這么多括號!
<p th:text="#{message}">default message</p>
<script th:inline="javascript">
var message = [[${message}]];
console.log(message);
</script>
方法二:隱藏域獲取
將參數(shù)放到隱藏域中在獲取
<p th:value="#{message}" type="hidden" id="data">default message</p>
//獲取隱藏域里面的參數(shù)
<script type="text/javascript">
var data=${"#data"}.val();
var data=$("#data").val();
</script>方法三:text文本獲取
<p th:text="#{message}" id="data"></p>
<script type="text/javascript">
var bankCard1=$("#data").text();
</script>Jquery獲取thymeleaf中checkbox的值
實現(xiàn)
thymeleaf頁面代碼
<button id="printBtn" class="btn btn-info mb_1em" type="button" onclick="return printDetails()"><i class="fa fa-paste"></i> 打印</button>
<table id="wmsInOrderDetail_table_id" class="table table-bordered hover" style="width:100%">
<thead>
<tr>
<th>序號</th>
<th>托盤編號</th>
<th>物料編號</th>
<th>物料名稱</th>
<th>數(shù)量</th>
<th>供應(yīng)商批次</th>
<th>生產(chǎn)日期</th>
<th>狀態(tài)</th>
</tr>
</thead>
<tbody >
<tr th:each="orderlist:${wmsReceiveOrderDetailsVOList}" >
<td>
<input type="checkbox"
class="ads_Checkbox"
th:text="${orderlist.id}"
th:value="${orderlist.id}" name="checkedid"/>
</td>
<td th:text="${orderlist.salverCode}"></td>
<td th:text="${orderlist.materielId}"></td>
<td th:text="${orderlist.materielName}"></td>
<td th:text="${orderlist.num}"></td>
<td th:text="${orderlist.supplierBatch}"></td>
<td th:text="${#dates.format(orderlist.productDate, 'yyyy-MM-dd HH:mm:ss')}"></td>
<td th:text="${orderlist.statusName}"></td>
</tr>
</tbody>
</table>選中數(shù)據(jù)后,點擊打印按鈕,來到j(luò)s中的方法。
function printDetails(){
debugger
var checkID = [];//定義一個空數(shù)組
$("input[name='checkedid']:checked").each(function(i){//把所有被選中的復(fù)選框的值存入數(shù)組
checkID[i] =$(this).val();
console.log(checkID);
});
}到此這篇關(guān)于使用Jquery獲取Thymeleaf參數(shù)的三種方式小結(jié)的文章就介紹到這了,更多相關(guān)Jquery獲取Thymeleaf參數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 使用jquery獲取url及url參數(shù)的簡單實例
- 使用jquery獲取url以及jquery獲取url參數(shù)的實現(xiàn)方法
- jquery獲取url參數(shù)及url加參數(shù)的方法
- jQuery獲取URL請求參數(shù)的方法
- 通過jquery 獲取URL參數(shù)并進行轉(zhuǎn)碼
- jQuery函數(shù)的第二個參數(shù)獲取指定上下文中的DOM元素
- javascript/jquery獲取地址欄url參數(shù)的方法
- jquery獲取URL中參數(shù)解決中文亂碼問題的兩種方法
- jQuery 獲取URL的GET參數(shù)值的小例子
- jQuery獲取地址欄參數(shù)插件(模仿C#)
相關(guān)文章
jQuery實現(xiàn)拖動調(diào)整表格單元格大小的代碼實例
這篇文章主要介紹了jQuery實現(xiàn)拖動調(diào)整表格單元格大小的代碼實例,本文直接給出實現(xiàn)代碼,需要的朋友可以參考下2015-01-01
jQuery中document與window以及l(fā)oad與ready 區(qū)別詳解
這篇文章主要介紹了jQuery中document與window以及l(fā)oad與ready 區(qū)別詳解,需要的朋友可以參考下2014-12-12

