国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JQuery Ajax動態(tài)加載Table數(shù)據(jù)的實例講解

2019-11-19 13:18:23
字體:
供稿:網(wǎng)友

我們在jsp定義一個select和一個table,要求實現(xiàn)根據(jù)select的選值,動態(tài)加載table數(shù)據(jù)。

<select id="type" name="type" onchange="reloadTable(this)"></select><table id="import-table" class="table table-striped table-bordered table-hover" width="100%"></table>

table第一次加載數(shù)據(jù)的function定義如下:

function loadData() { var c = '<label><input type="checkbox" id="checkbox1" class="ace" onchange="javascrpt:selectAll(this);"/><span class="lbl"></span></label>'; $('#import-table').DataTable({  ajax: {   url: '<%=request.getContextPath()%>' + "../../../hot/getByCode.action?code=APP",   type: "post",   dataType: "json",   data: {}  },  "scrollCollapse": true,  ordering: false,  visible: true,  api: true,  serverSide: true,  columns: [{   "data": "id",   "class": "center",   "width": "80px",   "name": "importId",   orderable: false,   "title": c,   "render": function(a, b, c, d) {    return getColumnReturnStr("checkbox", c.id, "importId")   }  },  {   "data": "name",   "title": "名稱"  },  ],  "dom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",  initComplete: function() {} });}

接著需要考慮,如何在select選值改變的時候,更新table中ajax的url地址,實現(xiàn)table的reload

function reloadTable(){  var code = $("#type option:selected").val(); $('#import-table').DataTable() .ajax.url(   '<%=request.getContextPath()%>'+"../../../hot/getByCode.action?code="+ code ).load();}

這樣我們便可以通過改變select選值,動態(tài)加載table數(shù)據(jù)。

通過$(‘#import-table').DataTable().ajax.url().load();方法實現(xiàn)。

以上這篇JQuery Ajax動態(tài)加載Table數(shù)據(jù)的實例講解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 漳平市| 广南县| 开原市| 贡嘎县| 田阳县| 大洼县| 宝山区| 黎平县| 江门市| 康定县| 尚志市| 庆阳市| 博罗县| 鹰潭市| 达孜县| 阿拉善右旗| 潢川县| 莫力| 民权县| 鄂温| 茂名市| 田阳县| 铅山县| 高青县| 房产| 安国市| 丹巴县| 秀山| 德化县| 兴安县| 河北省| 金堂县| 呼和浩特市| 台北县| 湖口县| 罗定市| 厦门市| 高碑店市| 宁乡县| 仪征市| 秦安县|