6
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 lines by clicking on them.
That part I didn’t understand
elemento.onclick = function()
{
Selecionar(this,cor);
};
Why does it call the function again? Actually I understand, it calls the function again because it is part of logic: it returns the default color of the line and unchecks ckbox.
But I do not understand, because for me when the function was called it was terminated, but when debugging I saw that when I click again on the line falls straight into that part of the function:
elemento.onclick = function () {
Selecionar(this, cor);
};
That I found a mystery, because as I said, for me the function was called and ended. I took a print of what appears when I click again on the line:
Can someone explain to me how this works? Why the function is not closed? If there were several functions, they would remain open?
Take a look at your stack trace, as you are with your active Debugger, you stopped running and after your select code was executed, the break point went to something in jquery. It has nothing to do with your onclick.
– Bruno Piovan
Could you please insert the HTML of your page? @Willian
– PauloHDSousa
Any results? Made progress on the problem?
– PauloHDSousa