Ver Mensaje Individual
  #5 (permalink)  
Antiguo 22/08/2007, 13:53
Avatar de derkenuke
derkenuke
Colaborador
 
Fecha de Ingreso: octubre-2003
Ubicación: self.location.href
Mensajes: 2.665
Antigüedad: 20 años, 7 meses
Puntos: 45
Re: Atributo 'checked' en checkbox

Bueno, te confieso que nunca he trabajado con ordenamiento de tablas, pero si el problema es que en FF no se modifica el innerHTML siempre se puede "forzar" a que lo haga cada vez que hagamos click en un checkbox.

Yo lo he conseguido en el siguiente ejemplo con éste código "sencillo":
Código PHP:
// Quitar o poner el atributo checked en los checkbox al cambiar su estado.
( function() {
    var 
inputs document.getElementsByTagName("input");
    for(var 
i=0i<inputs.lengthi++) {
        if( (
inputs[i].type == "checkbox") && (inputs[i].addEventListener) ) { // Se presupone estándar tipo Firefox, habría que probar otros navegadores.
            
inputs[i].addEventListener("click", function() {
                if( 
this.checked )
                    
this.setAttribute("checked""checked");
                else
                    
this.removeAttributeNodethis.getAttributeNode("checked") );
            }, 
false);
        }
    }
} ) (); 
Asignamos un evento onclick para cada checkbox y si acepta addEventListener (se presupone un navegador con DOM estándar) entonces eliminamos o colocamos su atributo checked en consecuencia.

Este ejemplo se ve completo cómo trabajaría:
Código PHP:
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<
head>
<
meta http-equiv="Content-type" content="text/html;charset=iso-8859-1" />
<
meta name="Author" content="derkeNuke" />
<
title>Página nueva</title>
<
style type="text/css">
</
style>
</
head>

<
body>

<
label id="elLabel"Checkbox
    
<input type="checkbox" checked="true" />
</
label> <br/>
<
button type="button" onclick="e($('elLabel').innerHTML)"Escribir su innerHTML en el documento </button> <br/>
<
button type="button" onclick="ponHTMLenPruebas($('elLabel').innerHTML)"Pon su innerHTML actual en el DIV pruebas</button> <br/>


<
div id="pruebas" style="border:solid 2px black;"DIV PRUEBAS <br/> </div>

<
script type="text/javascript">

// escribir en el documento.
function e(q,noBr) {
    
document.body.appendChilddocument.createTextNode(q) );
    if(!
noBrdocument.body.appendChilddocument.createElement("BR") );
}
// obtener elemento por id.
function $(x) { return document.getElementById(x); }


function 
ponHTMLenPruebas(HTML) {
    $(
"pruebas").innerHTML += HTML+" <br/>";
}

// Quitar o poner el atributo checked en los checkbox al cambiar su estado.
( function() {
    var 
inputs document.getElementsByTagName("input");
    for(var 
i=0i<inputs.lengthi++) {
        if( (
inputs[i].type == "checkbox") && (inputs[i].addEventListener) ) { // Se presupone estándar tipo Firefox, habría que probar otros navegadores.
            
inputs[i].addEventListener("click", function() {
                if( 
this.checked )
                    
this.setAttribute("checked""checked");
                else
                    
this.removeAttributeNodethis.getAttributeNode("checked") );
            }, 
false);
        }
    }
} ) ();


</script>

</body>
</html> 
No sé si es lo que buscas, pero al copiar su innerHTML a la capa pruebas se copia si realmente está checked o no, sin hacer comprobaciones de ningún tipo ni ralentizar el navegador más de la cuenta a la hora de hacer la operación.


Obviamente funciona en los dos navegadores (he probado en IE6 y FF2).



Entonces nos olvidaríamos de comprobaciones auxiliares a la hora de ordenar. ¿Quizás puedas arreglarlo así?
__________________
- Haz preguntas inteligentes, y obtendrás más y mejores respuestas.
- Antes de postearlo Inténtalo y Búscalo.
- Escribe correctamente tus mensajes.