function Selecionar(elemento,cordefundo)
{
var Inputs = elemento.getElementsByTagName("input");
var cor = elemento.style.backgroundColor; //manter a cor default do elemento
for(var i = 0; i < Inputs.length; ++i)
{
if(Inputs[i].type == 'checkbox')
{
Inputs[i].checked = !Inputs[i].checked;
elemento.style.backgroundColor = cordefundo;
elemento.onclick = function()
{
Selecionar(this,cor);
};
}
}
}
protected void gvSelecao_PreRender(object sender, EventArgs e){
GridView gv = (GridView)sender;
foreach (GridViewRow row in gv.Rows)
row.Attributes.Add("onclick", "Selecionar(this,'#FFFF00');");
}
I took these two codes from a website to make you select gridview rows by clicking on them.
This part I did not understand
elemento.onclick = function()
{
Selecionar(this,cor);
};
Why does he call the function again? Actually I understand, call the function again because it is part of the logic: it returns the default color of the line and unchecks the ckbox.
But I do not understand, because for me when the function was called it was closed, but when debugging I saw that when I click again on the line it falls directly into that part of the function:
elemento.onclick = function () {
Selecionar(this, cor);
};
What I found a mystery, because as I said, for me the function was called and closed. I took a print of what appears when I click again on the line:
Does anyone explain to me how this works? Why does not the function terminate? If they were several functions, would they remain open?