2013年9月12日星期四

Long time did not come to ask a simple JS problem - do not touch too long

Needs to survive I have a dynamic table row color need to implement Click Click Restore first line second line second line discoloration on.
code after clicking the Click to change color , but you can not restore hope JS expert help changed .
PS: TR can not be directly added to the client in the event in accordance with the following change Thank you.

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";
            }
        }
    }
}

------ Solution ------------------------------------- -------

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)
            }
        }
    }

------ For reference only ------------------------- --------------
your html code what to write ?
------ For reference only ------------ ---------------------------
asp.net. this code can click a row , but after clicking the color can not be restored and click on the other line color or click on a line in this effect to produce a line of color
------ For reference only ------------- --------------------------


where you want to be too simple. In the settings , you need the original value saved, for example,

this.old_x = this.x;
this.old_style_backgroundColor = this.style.backgroundColor;
this.old_color = this.color;
this.old_style_cursor = this.style.cursor;

In this way, when the other line is set, we must traverse the other lines , those lines this.color inconsistent with this.old_color all replies values.

------ For reference only ---------------------------------- -----
dynamically add custom attributes to scratch before the background color on it

------ For reference only ---------------------------------- -----
top of the two methods can be die
------ For reference only ---------------------- -----------------


t [i]. onclick = function () {

var trItems = this.Parent.getElementsByTagName ("tr"); ;/ / re- iterate reset these tr, which is the most earth approach , but can , huh

this.x = "0"; this.style.backgroundColor = (this.sectionRowIndex% 2 == ; 0)? a: b; this . color = "# ffffff"; this.style. cursor = "hand";

}

没有评论:

发表评论