Las casillas de verificación no se verifican en IE7 usando Javascript, y sin embargo no hay errores
Está bien, estoy totalmente confundido en este caso.
Tengo un script que recibe un montón de valores de un objeto JSON y crea un montón de casillas de verificación y marca o desactiva estas casillas de verificación en función de sus valores.
El script funciona correctamente en IE8, Firefox3, etc ... etc ...
Sin embargo...
En IE7, el script no puede marcar las casillas de verificación. No muestra errores y, por lo que puedo decir, el script se ejecuta bien. Simplemente no marca ninguna de las casillas de verificación, y no sé por qué ...
<code>shoppingCart['Update_Stock_Item_0_NRD%5FHAT2'] = { 'propeller': { 'label' : 'propeller', 'optionValues' : { 'on' : { 'selected': 'selected' }, 'off' : { 'selected': '' }, '' : new String() } }, 'sunLogo': { 'label' : 'sunLogo', 'optionValues' : { 'on' : { 'selected': 'selected' }, 'off' : { 'selected': '' }, '' : new String() } }, 'MSLogo': { 'label' : 'sunLogo', 'optionValues' : { 'on' : { 'selected': 'selected' }, 'off' : { 'selected': '' }, '' : new String() } } }; </code>
función stockInit () {alert ("BEGIN: stockInit ()"); // TODO: Recibirás una opción "on" y una opción "off", // One tendrá un atributo "seleccionado" de "selected", // y el otro tendrá un atributo "selected" de "" // // La opción que tiene el atributo "seleccionado" de "" // generará una casilla de verificación que no está marcada. // // La opción que tiene el "atributo seleccionado de" seleccionado "// generará una casilla de verificación que está marcada. //
// ¿Por qué? Lo preguntas ... porque así es como está // configurado. para (elemento var en shoppingCart) {// // console.log ("elemento de proceso:" + elemento);
<code> var optionContainer = document.getElementById(item + "_optionContainer"); for(var option in shoppingCart[item]) { if(option != "blank") { // // console.log("option: " + option); var currentOption = shoppingCart[item][option]['optionValues']; // // console.log("currentOption['on']['selected']: " + currentOption['on']['selected']); // // console.log("currentOption['off']['selected']: " + currentOption['off']['selected']); // Really you only have to check the one, but just to be through-o var selected = (currentOption['on']['selected'] == 'selected') ? true : false; selected = (currentOption['off']['selected'] == 'selected') ? false : true; var label = document.createElement("LABEL"); var labelText = document.createTextNode(shoppingCart[item][option]['label']); var optionInput = document.createElement("INPUT"); var hiddenInput = document.createElement("INPUT"); optionInput.setAttribute("type", "checkbox"); optionInput.checked = selected; optionInput.setAttribute("id", option); alert(optionInput.id); alert(optionInput.checked); hiddenInput.setAttribute("type", "hidden"); hiddenInput.setAttribute("name", option); hiddenInput.setAttribute("id", option + "_hiddenValue"); hiddenInput.setAttribute("value", (optionInput.checked) ? "on" : "off"); label.appendChild(optionInput); label.appendChild(labelText); label.appendChild(hiddenInput); (function(id) { optionInput.onclick = function() { var hiddenInput = document.getElementById(id + "_hiddenValue"); hiddenInput.setAttribute("value", (this.checked == true) ? "on" : "off"); alert("this.id: " + this.id); alert("this.checked: " + this.checked); } })(optionInput.id); optionContainer.appendChild(label); } } // // console.log("processing item of " + item + " complete"); } alert("END: stockInit()"); } </code>
Y, por favor, no preguntes por qué hago las cosas de esta manera ... todo lo que puedo decirte es que no tengo acceso al código de fondo ... así que obtengo lo que obtengo ...