JQuery通过AJAX从后台获取信息显示在表格上并支持行选中

不想用Easyui的样式,但是想要他的表格功能,本来一开始是要到网上找相关插件的,但是没找到就开始自己写,没想到这么简单。

后台代码:(这个不重要)

rush:js;"> public ActionResult GetDictTypes() { var data = from a in dbo.DictTypes select new DictTypeListviewmodel { ID = a.ID,Name = a.Name,LastChangeUser = a.LastChangeUser,LastChangeDate = a.LastChangeDate,Remark = a.Remark }; return Json(data.ToList()); }

页面代码

rush:js;"> ID

javascript代码:(需要在 $(document).ready(function ($){ } 里调用

rush:js;"> function ShowDictType() { $('#DictTypeTable').children('tbody').empty(); $.ajax({ url: GetDictTypes_URL,type: 'post',dataType: 'json' }) .done(function (data) { var tbody = ""; $.each(data,function (index,el) { var tr = "

要在表格生成之后再绑定事件:

rush:js;"> function BindDictTypeTableEvent() { $('#DictTypeTable tbody.sel').children('tr').click(function (event) { $(this).siblings('tr').removeClass('active');//删除其他行的选中效果 $(this).addClass('active');//增加选中效果 var id = $(this).children('td:eq(0)').text();//获取ID ShowDictData(id);//操作代码,这里是显示一个表格数据 }); }

最后这里是获取选中条目ID的代码

rush:js;"> function GetTypeTableSelectId() { return $('#DictTypeTable tbody.sel tr.active td:eq(0)').text(); }

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...
标题 简介