jquery Ajax之后绑定到table 并添加样式
来源:互联网 发布:视频网站程序 linux 编辑:程序博客网 时间:2024/05/16 09:50
第一次发帖 不足的地方请大家指出
HTML
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Tr5ansitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type"content="text/html; charset=gb2312"/> <title>Jquery</title> </head> <body> <table id="MFsdata"cellspacing="0px"> <thead> <tr id="MFstr"class="MFstr"> <th> 表头 </th> <th> 表头 </th>………… </tr> </thead> <tbody id="datas"> </tbody> </table> <div id="loading"style="top:50%; right:50%;position:absolute;padding:0px; margin:0px; z-index:999;"> <img src="../image/0.gif"alt="loading……"/> </div> </body> </html>
JS
//清空当前数据function clearRowsSMS() { $('#datas').empty();}function searchSMS() { clearRowsSMS(); //每次请求前先清空当前显示的数据 $("#loading").show(); //添加一个等待图标,提高用户体验 $.ajax({ type: "Post", //get方式请求 dataType: "json", //返回数据类型为json async: false, url: 'MFstock.ashx', data: "Str=" + PageIndex + "|" + SI, //要发送到后台的数据 cache: false, timeout: 6000, //超时时间:6秒 //请求错误 error: function() { $("#loading").show(); }, //请求成功 success: function(buffer) { var datas = buffer.r; //返回的数据 $("#loading").hide(); //隐藏当前图标 if (datas == undefined || datas == "") { $("#MFsdata").find('tfoot').append("<tr><td colspan='6' align='center'>数据错误</td></tr>"); } else { //循环显示数据 $.each(datas, function(idx, item) { var trColor; var tbBody = "<tr class='jsctr' id='" + idx + "' onclick='mo(" + idx + ")')>" tbBody += "<td class='throw'>" + item.s + "</td><td class='throw'><a href=javascript:fnMyChangeStock('" + item.a + "')> " + item.a + "</a></td> <td class='throw'>" + item.b + "</td>" //根据不同的数据 添加不同的样式 if (item.c > 0) { trColor = "red"; tbBody += "<td class='" + trColor + "'>" + forcheck(item.c) + "</td>" } else if (item.c == 0) { trColor = "green"; tbBody += "<td class='" + trColor + "'>" + forcheck(item.c) + "</td>" } else { trColor = "green"; tbBody += "<td class='" + trColor + "'>" + forcheck(item.c) + "</td>" } if (item.d > 0) { trColor = "red"; tbBody += "<td class='" + trColor + "'>" + forcheck(item.d) + "</td>" } else if (item.d == 0) { trColor = "white"; tbBody += "<td class='" + trColor + "'>" + forcheck(item.d) + "</td>" } else { trColor = "green"; tbBody += "<td class='" + trColor + "'>" + forcheck(item.d) + "</td>" } tbBody += "</tr>" $('#datas').append(tbBody); //添加到显示容器中 }); } } });}//保留两位小数function forcheck(x) { var f_x = parseFloat(x); if (isNaN(f_x)) { return x; } f_x = Math.round(f_x * 100) / 100; var s_x = f_x.toString(); var pos_decimal = s_x.indexOf('.'); if (pos_decimal < 0) { pos_decimal = s_x.length; s_x += '.'; } while (s_x.length <= pos_decimal + 2) { s_x += '0'; } return s_x;}
CSS
.throw { color: #FC6; font-size: 14px;}.red { color: Red; font-size: 14px;}.white { color: #FDFDFD; font-size: 14px;}.green { color: #0F0; font-size: 14px;}
- jquery Ajax之后绑定到table 并添加样式
- jquery 为 Table 添加样式
- jQuery用ajax请求json数据并绑定到表格
- 动态添加个table并绑定gridview
- Jquery/jqueryMobile接收数据,并将其添加到table中且覆盖掉重复行
- jquery 动态添加 tr 到 table
- jQuery请求json并绑定到表格
- 【asp.net小札记】jquery+ajax绑定数据库显示table
- Jquery实现动态绑定单击时间,动态添加样式
- 使用jquery当页面打开时,将一个事件绑定到控件(同时执行两个事件),并修改加载样式类中的样式
- XML绑定到Table
- Ajax成功添加新DOM元素 jquery 绑定元素事件
- JQUERY 通过AJAX获取数据并绑定下拉框
- 【JQUERY】默认样式添加之后自动添加click事件的解决办法
- strut,jsp动态添加table行,绑定table行数据到formbean
- jquery获取页面的TextBox并给添加样式
- 代码构建控件添加到界面并绑定数据
- jQuery实现动态添加tr到table的方法
- 提问
- Android stagefright decoder
- MYSQL主从同步异常汇总
- NetBeans相关
- SQL 行转列总结
- jquery Ajax之后绑定到table 并添加样式
- MySQL锁表机制分析
- JAVA EXCEL 数据 导入 ORACLE
- 面对面--谈需求获取过程(自学·不断更新)
- NCL简介和安装方法
- java EXCEL 数据 导入 Mysql
- ASN.1简介
- 内联函数
- 多线程