2013-11-27 213 views
-2

这是我的代码:为什么这个JavaScript不起作用?

function habilitarsistemas() { 
    if (document.getElementById("ChkSistemas").checked) 
     document.getElementById("tabelasistemas").style.display = "block"; 
    else 
     document.getElementById("tabelasistemas").style.display = "none"; 
} 

它正常工作与Firefox,但它不与IE和Chrome。为什么?

+2

因为它有错误。 –

回答

0

jQuery解决方案。

function habilitarsistemas() { 
    if ($('#ChkSistemas').is(':checked')) { 
    $('#tabelasistemas').css({ display: 'block' }); 
    } 
    else { 
    $('#tabelasistemas').css({ display: 'none' }); 
    } 
} 
+1

你能解释一下@ user3042318为什么这段代码比他好? –

+0

它有适当的开头和关闭,它是jQuery,我不是说它更好;) – mdesdev

+0

Tentei o script jQuery enviado pelo mdesdevporémnãofuncionou vou postar a parte docódigoonde se encontra tabel Aparentemente elenãoreconhece esse id 。

user3042318

0

它可能与只提供@name属性而不是@id的HTML标记有关吗? (有@name到@id的传统映射,但这在Chrome中不受支持。)