2012-06-09 89 views
0

我的JavaScript代碼替換Div標籤...彈出關閉後如何顯示成功消息?

<script type="text/javascript"> 
    function showPopup(url) { 
    newwindow=window.open(url,'Image   
Share','height=490,width=850,top=200,left=80,resizable'); 
    if (window.focus) {newwindow.focus()} 
     } 
    function replace() { 
    document.getElementById("div1").style.display="none"; 
    document.getElementById("div2").style.display="block"; 
} 
</script> 



<div id = "div1" style="display:block" onclick = "replace()"> 
123123123 
</div> 

<div id = "div2" style="display:none">454545454 </div> 

這一工程,但只有當我做一次。如果我重複這樣在同一頁上:

<!-- -------1------- --> 

<div id = "div1" style="display:block" onclick = "replace()"> 
123123123 
</div> 
<div id = "div2" style="display:none">454545454 </div> 


<!-- -------2------- --> 

<div id = "div1" style="display:block" onclick = "replace()"> 
123123123 
</div> 
<div id = "div2" style="display:none">454545454 </div> 

<!-- -------3------- --> 

<div id = "div1" style="display:block" onclick = "replace()"> 
123123123 
</div> 
<div id = "div2" style="display:none">454545454 </div> 

然後它不工作。我有超鏈接"div1"。我想在彈出窗口關閉後替換它,並用成功消息替換它,或者在彈出窗口打開後禁用超鏈接。

回答

0

這是行不通的,因爲您不止一次使用過相同的ID,一個元素的ID只能使用一次,所以您必須將重複元素ID更改爲div3和div4等......