2011-02-06 44 views
0

我想單擊按鈕時隱藏div,並在點擊鏈接時顯示它,但是發生的事情只是閃爍,無論是顯示還是隱藏它。無論我如何嘗試在頁面上更改其可見性,它都會這樣做:更改top:-1000px;頂部:0px;或可見性:對可見性隱藏:可見或使用顯示「」與「無」屬性。所有這些導致它出現(如果變得可見)閃光,或者消失(如果隱藏)閃光。div元素在調整可見性時閃爍

點擊一個鏈接時,顯示DIV,並在div提交表單時再次隱藏DIV調用JS函數,我調用JS功能。

任何線索爲什麼會發生這種情況?

有關的頁面,可能是相關的幾點:

- 一些元素的onLoad期間通過JavaScript繪製身體{},而不是那些含有這種元素,或者該元素本身。

- 這

<script language="JavaScript" src = "dashboard.js"> 
    </script> 

...是所謂的頭部分,並且包括以下功能

-I've也試圖把隱藏/顯示功能,在相關的DIV直接下html代碼,但沒有改變。

的.css爲DIV:

div#userRegistration{ 
    text-align: center; 
    width: 100%; 
    height: 150%; 
    position: absolute; 
    background-color: white; 
    z-index: 20; 
    top: -1000px; 
} 

JS函數來顯示 - 按照以下更新:

function userRegistration(){ 
    document.getElementById("userRegistration").style.top = '0px'; 
    return true; 
} 

JS函數隱藏(注意,這永遠也不會被使用,除非我能得到的div顯示並保持在第一位) - 更新:

function validateUserRegistration(){ 
    document.getElementById("userRegistration").style.display = 'none'; 
    return true; 
} 

更新的HTML(每下面2個建議):

 <div id="userRegistration"> 
      <h3>New User Registration:</h3> 
      <form style="text-align: left;" action="" onsubmit="return validateUserRegistration();"> 
       <table> 
        <tr> 
         <td> 
          Email: 
         </td> 
         <td> 
          <input type="text" name="userName"/> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          User Name: 
         </td> 
         <td> 
          <input type="text" name="userName"/> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          Password: 
         </td> 
         <td> 
          <input type="password" name="password"/> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          Repeat Password: 
         </td> 
         <td> 
          <input type="password" name="repeatPassword"/> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          &nbsp;&nbsp; 
         </td> 
         <td> 
          <input type="submit" name="submitRegistration" value="Submit"/> 
         </td> 
        </tr> 
       </table> 
      </form> 
     </div> 

編輯:重新加載頁面下面的空href =「」是什麼導致「閃光燈」。感謝techtheatre將此引起我的注意。/EDIT

HTML最初顯示的div(做同樣的浮華,事情時,試圖隱藏DIV,如果它已經在頁面加載可見的):

<div id="newUser"> 
    <a href="" onclick="return userRegistration();"> 

    New User? Register here. 

    </a> 
</div> 
+0

在表單中的onSubmit =「validateUserRegistration()」上,嘗試將onSubmit =「return validateUserRegistration ();」 – Will 2011-02-06 04:26:12

+0

試過了,沒有變化。 – etech22 2011-02-06 04:32:31

回答

1

添加return true;雙方結束的括號內的功能

編輯:

一件事......什麼是應該當您提交的形式出現呢?您已將操作留空。如果它提交回相同的頁面(這是它對當前的HTML所做的),整個頁面將重新加載。這會使其隱藏一瞬間,然後在頁面重新加載時重新出現。如果您嘗試在沒有頁面重新加載的情況下提交表單數據,則需要在AJAX調用中實現此操作...