2011-12-02 111 views
1

我試圖用一些顯示隱藏的功能在我的js文件:顯示功能沒有響應

$(document).ready(function() { 
    $('#me').hide(); 
    $('#send').click(function() { 
     $('#me').show("slow"); 
    }); 
}); 

出於某種原因,當我點擊ID =「發送」按鈕,將ID =「我「(圖片)

沒有顯示出來再(雖然它消失):

<div id="me"> 
    <img src="Me.JPG" alt="me" width="450" height="450" alt="picture" align="right"/> 
</div> 

幫助嗎?

請讓我知道,如果我不得不添加更多的代碼,使自己清楚......

謝謝!

編輯:

這裏是發送按鈕的代碼:我用這樣的

<input type="submit" id="send" value=" Send " class="submit" /> 
+1

您可以顯示發送按鈕的代碼。 – Will

+1

必須是更多的東西。對我來說工作得很好,我只是做了一個名爲send的'

+0

剛剛添加了提交按鈕代碼... – Itzik984

回答

1

我會說最可能的答案是send按鈕在您的頁面加載時尚不存在。這個按鈕是動態創建的還是通過其他機制創建的?爲了調試,我會說:

$(document).ready(function() { 
    $('#me').hide(); 
    alert(document.getElementById('send')); //Test if it exists 
    $('#send').click(function() { 
     $('#me').show("slow"); 
    }); 
    }); 

如果你得到null一個彈出窗口,那麼你就必須追查得知這個按鈕被生成並綁定事件出現。

除此之外,你可以分辨:

jsfiddle.net/zs7W2/

你的代碼工作正常。

UPDATE:

我相信你FORM實際提交本身。您應該更改您的代碼:

$(document).ready(function() { 
    $('#me').hide(); 
    $('#send').click(function() { 
     $('#me').show("slow"); 
     return false; //Prevent submit 
    }); 
    }); 

或者,使用<button type="button"><input type="button">

例子:http://jsfiddle.net/zs7W2/7/

+0

好吧,我再次打開html,我看到圖像正在加載,並在milisec後它再次消失...不知道爲什麼會發生這種情況 – Itzik984

+0

是的,聽起來你的表單正在提交,因此整個頁面重新加載。你可以把''改成'

1
<div id="me"> 
<img src="Me.jpg" alt="me" width="450" height="450" alt="picture" align="right"/> 
</div> 
<input type="button" id="send" value="Submit"> 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
<script> 
$(document).ready(function() { 
    $('#me').hide(); 
    $('#send').click(function() { 
     $('#me').show("slow"); 
    }); 
    }); 

</script> 

。有用。我想這與圖像對齊有一些問題。嘗試改變它。