2013-10-30 60 views
0

我有一個頁面上顯示一起以下DIV元素能見度DIV內容:如何顯示基於的另一個DIV內容

<div><a href="javascript:;" id="awesome-button" style="visibility:hidden">This Link Shows Up First</a></div> 

<div style="display:none; id:showUpAfterAwesomeButtonIsClicked;"><a href="javascript:;" onclick="someFunction();">This is the value that should show up after the link above is clicked.</a></div> 

正如你所看到的,會首先顯示在頁面加載This Link Shows Up First文本。我有以下JavaScript確定用戶是否點擊了This Link Shows Up First文本。目標是如果隱藏awesome-button,則顯示This is the value that should show up after the link above is clicked div。

custom.valueAwesome = function() { 
var awesomeButton = document.getElementById('awesome-button'); 
awesomeButton.style.visibility = 'hidden'; 
document.getElementById("showUpAfterAwesomeButtonIsClicked").style.display = ''; 
gadash.executeCommandQueue(); 
}; 

我已經測試過這個腳本,它成功地改變了showUpAfterAwesomeButtonIsClicked鏈路的狀態時隱時現的鏈接,用戶點擊。這使我相信,需要更新的連接與此線做:

document.getElementById("showUpAfterAwesomeButtonIsClicked").style.display = '';

我已經試過這條線的幾個變化。有沒有更好的方法來實現這個結果?謝謝。

回答

0

你不能在CSS中設置一個id屬性。它實際上需要是xml標籤上的一個屬性。 變化

<div style="display:none; id:showUpAfterAwesomeButtonIsClicked;"> 

<div id="showUpAfterAwesomeButtonIsClicked" style="display:none; "> 

這將使你的document.getElementById實際選擇它。

+0

謝謝,這樣做更有意義。我試着調整'id'的值,但是'display'沒有改變。我應該爲此寫一個單獨的javascript函數嗎? – Presto

+0

明白了!我不得不做出一些腳本調整,但你的回答肯定指向了正確的方向,所以我獲得了獎勵。非常感激 :) – Presto

相關問題