62,266
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
//颜色值推荐使用Hex,如 #f00 或 #ff0000
window.onload = function () {
GridViewColor("<%=gvList.ClientID%>", "#fff", "#eee", "#6df", "#fd6");
}
//GridView ID, 正常行背景色,交替行背景色,鼠标指向行背景色,鼠标点击后背景色
function GridViewColor(GridViewId, NormalColor, AlterColor, HoverColor, SelectColor) {
//获取所有要控制的行
var AllRows = document.getElementById(GridViewId).getElementsByTagName("tr");
//设置每一行的背景色和事件,循环从1开始而非0,可以避开表头那一行
for (var i = 1; i < AllRows.length; i++) {
//设定本行默认的背景色
AllRows[i].style.background = i % 2 == 0 ? NormalColor : AlterColor;
//处于选中状态的行发生这两个事件时不改变颜色
if (HoverColor != "") {
AllRows[i].onmouseover = function () { if (!this.selected) this.style.background = HoverColor; }
if (i % 2 == 0) {
AllRows[i].onmouseout = function () { if (!this.selected) this.style.background = NormalColor; }
}
else {
AllRows[i].onmouseout = function () { if (!this.selected) this.style.background = AlterColor; }
}
}
//如果指定了鼠标点击的背景色,则添加onclick事件
//在事件响应中修改被点击行的选中状态
if (SelectColor != "") {
AllRows[i].onclick = function () {
this.style.background = this.style.background == SelectColor ? HoverColor : SelectColor;
this.selected = !this.selected;
}
}
}
}
</script>
实现思路:
1.加载js判断上传用户是否点击了某行数据,ID是否存在,如果存在
根据读取的ID,定位到与girdView相同ID行上。
2.使用js获取用户点击的那行数据ID并保存到表中var girdView= document.getElementById('girdView');
girdView.onload = function () {
girdView.contentWindow.scrollTo(x,y);
}