需求.我有一个动态生存的table 需要实现点击一行变色 点击第2行第一行还原 第2行变色 类推。
代码实现了点击变色 但是点击之后无法还原 希望JS高手帮忙改改。
PS: 不能直接在TR中加入客户端事件 按照下面这个 改 谢谢。function senfe(o, a, b, c)
{
var t = document.getElementById(o)
if (t != null)
{
t = t.getElementsByTagName("tr");
for (var i = 1; i < t.length; i++)
{
var bool = true;
t[i].onclick = function()
{
this.x = "0";
this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? a : b;
this.color = "#ffffff";
this.style.cursor = "hand";
}
t[i].onmouseover = function()
{
if (this.x != "1")
this.style.cursor = "hand";
}
}
}
}
代码实现了点击变色 但是点击之后无法还原 希望JS高手帮忙改改。
PS: 不能直接在TR中加入客户端事件 按照下面这个 改 谢谢。function senfe(o, a, b, c)
{
var t = document.getElementById(o)
if (t != null)
{
t = t.getElementsByTagName("tr");
for (var i = 1; i < t.length; i++)
{
var bool = true;
t[i].onclick = function()
{
this.x = "0";
this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? a : b;
this.color = "#ffffff";
this.style.cursor = "hand";
}
t[i].onmouseover = function()
{
if (this.x != "1")
this.style.cursor = "hand";
}
}
}
}
解决方案 »
- 关于资料搜索的问题
- Url重写网页之后,放到服务器上无法实现重写。
- 我怎么样能延迟2秒执行onmouseover事件。
- 使用Dropdownlist的Selectedindexchange事件来改变三个textbox的值,最简便得办法是怎么做
- Response.WriteFile方法,该怎样理解?
- Label显示数据库内容(限制内容文字数量)?
- 请问添加和修改记录时,用存储过程和用sql 语句 在性能上有区别吗?
- datagrid翻页的时候到底有没有再次查询数据库?
- 未将对象引用设置到对象的实例。
- xml简单问题高手 帮帮 忙在线 等(立刻揭帖 急~~~~~~~~~~~~~)
- “上级”和“下级”浏览器功能是什么意思
- 关于JS动态生成input,后台获取值的问题
这里你想得太简单了。在设置之前,需要把原值保存起来,例如 this.old_x = this.x;
this.old_style_backgroundColor = this.style.backgroundColor;
this.old_color = this.color;
this.old_style_cursor = this.style.cursor;这样,当别的行被设置时,就要遍历其它行,将那些 this.color 与 this.old_color 不一致的行全都回复值。
var FocusTrNum = -1; function senfe(o, a, b, c) {
var t = document.getElementById(o).getElementsByTagName('tr');
if (t != null) {
for (i = 0; i < t.length; i++) { var bool = true; t[i].onclick = function (n) {
return function () {
if (FocusTrNum != -1 && FocusTrNum != n) {
t[FocusTrNum].style.backgroundColor = '';
FocusTrNum = n;
} this.style.backgroundColor = t[n].sectionRowIndex % 2 == 0 ? a : b;
this.style.color = "#fff";
this.style.cursor = "pointer"; FocusTrNum = n;
};
}(i); t[i].onmouseover = function (n) {
return function () {
if (this.x != "1") {
this.style.cursor = "pointer";
}
}
}(i)
}
}
}