2014-09-06 130 views
0

所以我試圖加載與我的主頁在同一文件夾中的頁面,並且它不會在點擊時加載。也許我的代碼有問題。我知道這是因爲我用警報檢查它。Div內容無法加載點擊

代碼波紋管。

<script> 
    function closeIt() { 
      e.preventDefault(); 
      $("#load-here").load($(this).attr('secound.html')); 
    }; 
</script> 

<div id="buttons" > 
       <form> 
       <button class="btn" onClick="closeIt()" >secound</button> 
       </form> 
      </div> 

<div id="load-here"> 
    hehehe 
    </div> 
+0

您有一個名爲'closeIt'的函數,它通過ajax加載內容? '$(this).attr('secound.html')'應該做什麼? (http://api.jquery.com/attr/) – Pevara 2014-09-06 21:02:00

+0

即時消息不使用ajax; /也許我應該使用ajax? – vivid 2014-09-06 21:22:01

+0

你正在使用ajax,加載基本上只是一個簡寫。我實際上指的是可憐的名字選擇,你沒有關閉任何東西...... – Pevara 2014-09-06 21:24:31

回答

2

這裏有幾個問題。首先,您的函數closeIt不是jQuery事件處理程序,因此e尚未定義,您無法在其上調用preventDefault()。其次,您正在濫用attr,它用於從DOM元素獲取屬性。將closeIt的函數定義替換爲以下內容:

function closeIt() { 
    $("#load-here").load('secound.html'); 
}