Ver Mensaje Individual
  #4 (permalink)  
Antiguo 21/08/2012, 01:10
Avatar de dontexplain
dontexplain
 
Fecha de Ingreso: junio-2012
Mensajes: 536
Antigüedad: 12 años
Puntos: 127
Respuesta: como cambiar codigo javascript a jquery puro

for(var i = 0 ; i < document.getElementsByName("chk").length; i++)
calcular(document.getElementsByName("chk")[i], 1);
}


######################

d=$("chk");
$.each(d,function(i,v){
calcular($(v),1);
});


-----------------------------------

function calcular(obj, opc){
if(opc==1)
obj.checked = (document.getElementById("chk_todos").checked==tru e)?true:false;
var val = (obj.checked == true)? obj.id.split("_")[1] : 0;
obj.value = val;
document.getElementById("text_"+ obj.id.split("_")[1]).value = val;
}

####################################

function calcular(obj, opc){
if(opc==1){

$(obj).attr("checked") = ($("#chk_todos").attr("checked")==true)? true : false;
var val = ( $(obj).attr("checked") == true)? $(obj).attr("id").split("_")[1] : 0;
$(obj).val(val);
$("#text_"+$(obj).attr("id").split("_")[1]).val(val);
}

}

Un saludo.
__________________
21añero.
HTML/CSS, PHP, JS/jQuery, Mysql; NodeJS/Socket.io (& V8); C++ ; Python (wxpy); Ensamblador.
Músico (clarinetista/pianista) y compositor