function OperateData(data) { this.data = data; } OperateData.prototype = { constructor: OperateData, addData: function (name, phone) { var data = { id: 'ID' + new Date().getTime(), name: name, phone: phone }; this.data.push(data); CreateDom.prototype.creaTr.apply(this); }, delData: function (index) { this.data.splice(index, 1); CreateDom.prototype.creaTr.apply(this); return this.data.length; }, editData: function (index, id, name, phone) { this.data[index] = { id: id, name: name, phone: phone }; CreateDom.prototype.creaTr.apply(this); }, clearData: function () { this.data = []; CreateDom.prototype.creaTr.apply(this); } }
function CreateDom(data) { this.data = data; } CreateDom.prototype.creaTr = function () { var str = ''; for (var i = 0; i < this.data.length; i++) { str += '
'; str += '
' + this.data[i].id + '
'; str += '
' + this.data[i].name + '
'; str += '
' + this.data[i].phone + '
'; str += '
'; str += '
'; } str += '
'; str += ''; str += '
'; $('#showData').html(str); };
var index = 0; $(function () { var tr = new CreateDom(data); var oper = new OperateData(data); tr.creaTr();
$('#addStuInfoBtn').on('click', function () { var _name = $('#inputName').val(); var _phone = $('#inputPhone').val(); oper.addData(_name, _phone); $('#inputName').val(''); $('#inputPhone').val(''); $('#table').show(); $('#warning').hide(); });
$('#showData').on('click', '.btn-del', function () { index = $(this).parent().parent().index(); $('#tips').text('您确定要删除吗???'); showOrHide(); });
$('#showData').on('click', '.btn-edit', function () { index = $(this).parent().parent().index(); var _phone = $(this).parent().prev().text(); var _name = $(this).parent().prev().prev().text(); $('#inputName').val(_name); $('#inputPhone').val(_phone); $('#addStuInfoBtn').hide(); $('#confirEditBtn').show(); });
$('#confirEditBtn').on('click', function () { var _id = 'ID' + new Date().getTime(); var _name = $('#inputName').val(); var _phone = $('#inputPhone').val(); oper.editData(index, _id, _name, _phone); showOrHide(); });
$('#showData').on('click', '.btn-trash', function () { index = -2; $('#tips').text('您确定要清空吗???'); showOrHide(); });
$('#confimBtn').on('click', function () { if (index === -2) { oper.clearData(); $('#table').hide(); $('#warning').show(); return; } var len = oper.delData(index); if (!len) { $('#table').hide(); $('#warning').show(); } });
function showOrHide() { $('#addStuInfoBtn').show(); $('#confirEditBtn').hide(); $('#inputName').val(''); $('#inputPhone').val(''); } }) })(jQuery);
用原型函数(prototype)可以定义一些很方便的自定义函数,实现各种自定义功能。本次主要是实现了Array的去重、获取最大值和最小值。
实现代码如下:
<script type="text/javascript">
Array.prototype.unique = function() {
var a = {};
var le
ORACLE
下面这个效率很低
SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM IPAY_RCD_FS_RETURN order by id desc) A ) WHERE RN <20;
下面这个效率很高
SELECT A.*, ROWNUM RN FROM (SELECT * FROM IPAY_RCD_
Reverse a singly linked list.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
p