2013-07-05 33 views
0

我想加載一個HTML文件在<div id="content"></div>在按鈕點擊使用AJAX和jQuery,但點擊不加載它。下面是代碼:加載頁面上的按鈕點擊特定的div區域使用jquery

<body>  
<div id="header">  
<div id="radio"> 
    <input type="radio" id="navmenu1" name="radio"><label for="navmenu1">Home</label> 
    <input type="radio" id="navmenu2" name="radio"><label for="navmenu2">Contact</label> 
    <input type="radio" id="navmenu3" name="radio"><label for="navmenu3">Resume</label> 
</div> 
<div id="social"> 
    <a href="https://www.facebook.com/han.chang.10" target="new"><img src="img/facebook.png" class="facebook" alt="Facebook" /></a> 
    <a href="http://www.linkedin.com/pub/han-chang/58/959/a74/"><img src="img/linkedin.png" class="linkedin" alt="linkedin" /></a> 
    <a href="http://www.linkedin.com/pub/han-chang/58/959/a74/"><img src="img/twitter.png" class="twitter" alt="twitter" /></a> 
    <a href="mailto:[email protected]"><img src="img/gmail.png" class="gmail" alt="gmail" /></a> 
</div> 
</div><!--head--> 

<div id="content-area"> 
    <div id="content"></div>  
</div> 

<div id="footer-row"> 
    <footer> 
     <div id="footer-row-1"> 
     <ul id="footer"> 
      <li>&copy 2013</li> 
     </ul> 
     </div> 
    </footer> 
</div> 
</body> 

home.js如下:

$(function(){ 
    $("#radio").buttonset({ 
    $("#content").load("Page1.cshtml"); 
}); 
}) 
+0

看起來是一個MVC視圖(擴展名爲.csthml) - 這將無法正常工作...您需要加載使用視圖本身的頁面 – Darren

回答

0

你有幾個問題。

首先,你的jQuery無效。爲什麼$("#content).load("Page1.csthml");在JavaScript對象中間自行懸掛?

JavaScript對象,或在作爲選項傳入至少的,一般有以下格式:

{ 
    property1 : "value1", 
    property2 : "value2 
} 

你的「對象」只有一個屬性或值,但不能同時使用。我認爲你正在尋找這樣的:

$(function() { 
    $("#radio").buttonset(); 

    $("#radio").click(function() { 
     $("#content).load("Page1.csthml"); 
    }); 
}) 

但是,你有一個更多的問題還是:你不能直接調用.cshtml文件,你需要調用一個使用.cshtml控制器動作,因爲它的視圖。

+0

我明白了,所以我可以加載html而不是cshtml,如果我想要加載cshtml,我必須使用控制器操作。謝謝 – user2460718

相關問題