62,067
社区成员
发帖
与我相关
我的任务
分享
window.onload=function() {
var lastIndex=-1;
var tb=document.getElementById("setTbl");
for(var i=1;i<tb.rows.length;i++) {//从1开始,假设有列头
(function(row,i){
row.onclick=function(e) {
e=window.event ||e;
e.cancelBubble = true;
if(e.shiftKey) {
if(lastIndex==-1) {
this.className="hl";
lastIndex=this.rowIndex;
}else if(lastIndex==this.rowIndex) {
this.className="";lastIndex=-1;
} else {
var start=Math.min(this.rowIndex,lastIndex);
var end=Math.max(this.rowIndex,lastIndex);
for(var i=start;i<end;i++) {
tb.rows[i].className="hl";
}
lastIndex=this.rowIndex;
}
}else if(e.ctrlKey) {
this.className="hl";
} else {
for(var i=0;i<tb.rows.length;i++) {
tb.rows[i].className="";
}
this.className="hl";
lastIndex=this.rowIndex;
}
}
})(tb.rows[i],i);
}
}
呵呵我这样调用?
.hl,.hl a {background-color:#326496;color:#FFFFFF;}
(function() {
var lastIndex=-1;
var tb=document.getElementById("tb1");//表格的id可以写成"<%=GridView1.ClientID%>"
for(var i=1;i<tb.rows.length;i++) {//从1开始,假设有列头
(function(row,i){
row.onclick=function(e) {
e=window.event ||e;
e.cancelBubble = true;
if(e.shiftKey) {
if(lastIndex==-1) {
this.className="hl";
lastIndex=this.rowIndex;
}else if(lastIndex==this.rowIndex) {
this.className="";lastIndex=-1;
} else {
var start=Math.min(this.rowIndex,lastIndex);
var end=Math.max(this.rowIndex,lastIndex);
for(var i=start;i<end;i++) {
tb.rows[i].className="hl";
}
lastIndex=this.rowIndex;
}
}else if(e.ctrlKey) {
this.className="hl";
} else {
for(var i=0;i<tb.rows.length;i++) {
tb.rows[i].className="";
}
this.className="hl";
lastIndex=this.rowIndex;
}
}
})(tb.rows[i],i);
}
})();
var currTR=this;
function overTR(){
var trs = document.getElementById("setTbl").getElementsByTagName("tr");
for(var i in trs){
trs[i].onmouseover = function(){
var oldBgColor=this.bgColor;
var oldFontColor=this.style.color;
this.bgColor = "#0000FF";
this.style.color="#FFFFFF";
if(currTR != this&&currTR.tagName=="TR"){currTR.bgColor = oldBgColor; currTR.style.color=oldFontColor;}
currTR = this;
}
}
}
window.onload = function(){overTR();}
JS的行高亮