jQuery插件开发-table插件开发
2018-02-17 14:47
183 查看
使用过bootstarp-table插件的人都知道bootstrap给我们提供了一个非常好看的表格渲染插件,我基于此,也模拟开发了一个比较简单的表格渲染插件。
html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>组件</title>
<link rel="stylesheet" type="text/css" href="future.table.css"/>
<script src="./jquery-1.11.0.min.js"></script>
<script src="future.table.data.js"></script>
<script src="test.js"></script>
<style>
.one{color:red;}
.two{color:green;}
.live{color:blue;}
</style>
</head>
<body class="">
jQuery插件学习
<div id="demo"></div>
</body>
</html>test.js(插件调用)
//插件调用
$(function(){
var data = [
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555}
];
$("#demo").ftTData({
data:data,
cols:[{th:"col1",thName:"col1列名",fColor:"red",fWeight:"bolder"},
{th:"col2"},
{th:"col3"},
{th:"col4"},
{th:"col5"}]
});
});future.table.data.js(渲染数据插件)(function($){
$.extend(
{ftSay:function(option){
alert(option)}
});
$.fn.extend({
ftDivClear:function(){
this.html("11111");
//$(this).html("");
}
});
$.fn.extend({
ftTData:function(options){
//要被渲染的对象,this指向调用该函数的dom对象
$(this).html("");
var tableCols = options.cols;
var tableData = options.data;
var _html = "<table class='fttable_body'>";
$.each(tableData,function(dataIndex,data){
_html += "<tr>";
$.each(tableCols,function(colIndex,col){
_html += "<td style = '";
if(col.fColor != undefined){
_html += "color:" + col.fColor + ";";
}
if(col.fWeight != undefined){
_html += "font-weight:" + col.fWeight + ";";
}
_html += "'>";
_html += data[col.th];
_html += "</td>";
});
_html += "</tr>";
});
_html += "</table>";
$(this).html(_htm
4000
l);
}
});
})(jQuery);到此为止,运行,结果如下:
html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>组件</title>
<link rel="stylesheet" type="text/css" href="future.table.css"/>
<script src="./jquery-1.11.0.min.js"></script>
<script src="future.table.data.js"></script>
<script src="test.js"></script>
<style>
.one{color:red;}
.two{color:green;}
.live{color:blue;}
</style>
</head>
<body class="">
jQuery插件学习
<div id="demo"></div>
</body>
</html>test.js(插件调用)
//插件调用
$(function(){
var data = [
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555},
{col1:1111,col2:2222,col3:3333,col4:4444,col5:5555}
];
$("#demo").ftTData({
data:data,
cols:[{th:"col1",thName:"col1列名",fColor:"red",fWeight:"bolder"},
{th:"col2"},
{th:"col3"},
{th:"col4"},
{th:"col5"}]
});
});future.table.data.js(渲染数据插件)(function($){
$.extend(
{ftSay:function(option){
alert(option)}
});
$.fn.extend({
ftDivClear:function(){
this.html("11111");
//$(this).html("");
}
});
$.fn.extend({
ftTData:function(options){
//要被渲染的对象,this指向调用该函数的dom对象
$(this).html("");
var tableCols = options.cols;
var tableData = options.data;
var _html = "<table class='fttable_body'>";
$.each(tableData,function(dataIndex,data){
_html += "<tr>";
$.each(tableCols,function(colIndex,col){
_html += "<td style = '";
if(col.fColor != undefined){
_html += "color:" + col.fColor + ";";
}
if(col.fWeight != undefined){
_html += "font-weight:" + col.fWeight + ";";
}
_html += "'>";
_html += data[col.th];
_html += "</td>";
});
_html += "</tr>";
});
_html += "</table>";
$(this).html(_htm
4000
l);
}
});
})(jQuery);到此为止,运行,结果如下:
相关文章推荐
- [jQuery插件开发][dynamicTable2.0]根据JSON数据自动生成HTML Table
- jquery插件开发尝试(二)
- 12款经典的白富美型—jquery图片轮播插件—前端开发必备
- jQuery的插件开发的动态仪表板效果
- jQuery插件开发的模式和结构
- jQuery插件开发全解析,jQuery.extend , (function($){ , $.fn.pluginName
- jQuery的插件开发的动态仪表板效果
- jQuery插件开发及jQuery.extend函数详解和jQuery.fn与jQuery.prototype区别
- jQuery插件开发 格式与解析2
- 前端开发:一个开源、简单易用的jQuery表格插件(DataTables)
- jQuery插件开发模式
- 合并table相同单元格的jquery插件分享(很精简)
- jQuery插件开发精品教程,让你的jQuery提升一个台阶
- JQuery 插件开发的入门介绍
- 自己写了一个支持粘贴复制,类似excel的jquery table小插件
- jQuery插件开发
- 浅谈jquery插件开发模式*****************************************************************************************
- jquery插件开发之实现google+圈子选择功能
- 【JQuery,前端】jQuery插件开发精品教程,让你的jQuery提升一个台阶
- jQuery插件开发