2014-09-24 95 views
0

我一直在玩javascript,我試圖讓下面的工作。Javascript取消隱藏元素Onclick

<script type="text/javascript"> 
     function unhide(a) { 
       document.getElementById(a).style.visibility = "visible"; 
       document.getElementById(a).style.display=block; 
     } 
</script> 

<a onClick="unhide('id1')"><span> Remove</span> 

<span id="id1" hidden="true">Are You sure? | <a href="/forum/remove/id1"> Yes</a>/<a>No</a> </span> 

點擊,我試圖讓隱藏的元素得到顯示。我不確定它爲什麼不起作用,這個邏輯對我來說似乎是正確的。

乾杯

+0

嘗試使用document.getElementById(a).style.display =「block」; – VPK 2014-09-24 05:53:49

+0

你能解釋一下這段代碼的目的嗎?我的意思是你想在這裏做什麼。因爲我的代碼是完全混亂的兄弟。 :) – 2014-09-24 05:57:57

回答

0
function unhide(a) { 
      document.getElementById(a).style.visibility = "visible"; 
      document.getElementById(a).style.display="block"; 
    } 

塊是不確定的, 「堵」 不是

0

您正在使用hiddenhtml5 property具有limited browser compatibility截至目前。嘗試使用通過您的函數的onclick事件更改的css屬性visibilty:hidden來初步隱藏它。

function unhide(a) { 
 
    document.getElementById(a).style.visibility = "visible"; 
 
    document.getElementById(a).style.display=block; 
 
}
<a onClick="unhide('id1')"><span> Remove</span> 
 

 
<span id="id1" style="visibility:hidden;">Are You sure? | <a href="/forum/remove/id1"> Yes</a>/<a>No</a> </span>

0

我希望這將幫助你

<script type="text/javascript"> 
     function unhide(a) { 
       document.getElementById(a).style.display = 'block'; 
     } 
</script> 

<a href="javascript:void(0)" onClick="unhide('id1')">Remove</a> 

<span id="id1" style="display: none;">Are You sure? | <a href="/forum/remove/id1"> Yes</a>/<a>No</a> </span> 

讓我知道。

問候。

0

只有一點:
<script>標籤,都沒有引用的話是一個保留字或variable.So代碼

document.getElementById(a).style.display=block; 

應該是:

document.getElementById(a).style.display='block'; 

becase的block是顯示的屬性,而不是其他。

0

您正在使用隱藏屬性。

所以使用這個代碼,而不是:

function unhide(a){ 
    document.getElementById(a).removeAttribute('hidden'); 
} 
0

試試這個:

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 
window.onload = function(){ 
$("#id1").hide(); 
}; 

$("#unhide").click(function(){ 
$("#id1").show(); 
}); 
</script> 

<a id="unhide"><span> Remove</span></a> 
<span id="id1">Are You sure? | <a href="/forum/remove/id1"> Yes</a>/<a>No</a> </span> 

我希望這可以幫助您,請發表評論,如果它的工作與否。