$(function() {
initErpSort();
});
function initErpSort() {
$("th.erp_sort").each(function() {
this.style.cursor = 'pointer';
this.innerHTML = "<div>" + this.innerHTML + "</div>";
this.onmouseover = function() { this.style.backgroundPosition = '0px -24px'; };
this.onmouseout = function() { this.style.backgroundPosition = '0px 0px'; };
this.sort = '';
this.onclick = function() {
var d = this.getAttribute('data');
if (!d) return;
var p = this.parentNode.getElementsByTagName('div');
for (var i = 0; i < p.length; ++i)
p[i].className = '';
if (this.sort == 'desc') this.sort = 'asc';
else this.sort = 'desc';
this.getElementsByTagName('div')[0].className = this.sort;
OrderBySelect('order by ' + d + ' ' + this.sort);
};
});
}
使用
<tr>
<th >序号</th>
<th class="erp_sort" data="CompanyName">公司简称</th>
<th class="erp_sort" data="CoDep_forShort">部门简称</th>
<th class="erp_sort" data="AppYear">年度</th>
<th class="erp_sort" data="AppMonth">月份</th>
</tr>
function OrderBySelect(obj) {
OrderBySelectStr = obj;
ErpPageChage();
}