2016-08-07 12 views
1

ボタンをクリックすると3つのdivを非表示にしようとしていますが、jsが機能していません。"document.getElementById(div).style.display = none"が機能しない

function display() { 
    document.getElementById("Contentable").style.display = none; 
    document.getElementById("savebtn").style.display = none; 
    document.getElementById("stylebar").style.display = none; 
    } 

私がボタンをクリックすると、 "none"が定義されていないキャッチされていない参照エラーがあります。

+2

のように、二重または単一引用符"none"noneを記述する必要が;'、今構文エラーがあります。 – adeneo

+0

正しい、var noneは定義されていません –

+0

うわー、それに気付かなかった。私の考えでは、巨大な脳の部分があります。 – cosmo

答えて

3

として考慮され、引用符でなければなりません。

function display() { 
    $("#Contentable").hide(); 
    $("#savebtn").hide(); 
    $("#stylebar").hide(); 
    } 
3

"none"を文字列として渡す必要があります。

function display() { 
    document.getElementById("Contentable").style.display = 'none'; 
    document.getElementById("savebtn").style.display = 'none'; 
    document.getElementById("stylebar").style.display = 'none'; 
} 

それ以外の場合は、この場合定義されていない変数名として解釈されます。

-1

noneは、それ以外の場合は、どれもが" "であってはならないとあなたにも、このためにjQueryのを使用することができ、可変

element.style.display = 'none';

2

あなたは `.display = "none" をしないことになっています。この

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<style> 
 
#myDIV { 
 
    width: 500px; 
 
    height: 500px; 
 
    background-color: lightblue; 
 
} 
 
</style> 
 
</head> 
 
<body> 
 

 

 
<button onclick="myFunction()">Try it</button> 
 

 
<div id="myDIV"> 
 
This is my DIV element. 
 
</div> 
 

 

 
<script> 
 
function myFunction() { 
 
    document.getElementById("myDIV").style.display = "none"; 
 
} 
 
</script> 
 

 
</body> 
 
</html>

関連する問題