2012-03-15 52 views
0

我正在開發一個基於web的應用程序,其中我在頁面左側有兩個超鏈接,我在尋找的是當我點擊一個超鏈接應該加載another.jsp的內容並將其顯示在present.jsp上,如果我點擊下一個超鏈接,它應該對present.jsp上的third.jsp執行相同的操作。在超鏈接點擊後在當前jsp頁面中顯示另一個jsp內容

我發現一些像計算器: -

javascript--

function showItem(url) { 
$('#right-pane').load(url); 

}

鏈接 - < A HREF = 「showItem('another.jsp)」>第1項

其中「右窗格」是div標籤的id,我希望顯示另一個jsp內容。

< div id="right-pane" style="position: absolute; width: 988px; height: 649px; z-index: 2; left: 193px; top: 4px"> 

< /div> 

但是當我點擊項目1其saying--所請求的資源(/test1/showItem('another.jsp'))不可用。

我使用apache tomcat作爲服務器。

感謝, 艾爾沙德

+0

有包括你的jquery.js如果查不出來http://docs.jquery.com/How_jQuery_Works – Kimtho6 2012-03-15 12:06:31

+0

喜金,是的,我已經添加,如: - <腳本類型= 「文本/ JavaScript的」 SRC = 「的jquery.js」> <腳本類型= 「文本/ JavaScript的」> 功能showItem(URL){ $( '#右窗格')。負載( URL); } 在頭部區域 。 – Ars 2012-03-15 12:25:59

+0

然後看到我的答案;) – Kimtho6 2012-03-15 12:26:23

回答

3

添加一個class和id牛逼你的鏈接

< a href="'another.jsp" class="link1">item 1</a> 

添加到您的標題:

$(document).ready(function() { 
    $(".link1").click(function(event){ 
     event.preventDefault(); 
     var url =$(this).attr("href"); 
     $('#right-pane').load(url); 
    }); 
}); 

試試這個<script type="text/javascript" src="jquery.js">線改爲

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> 

tryed和IE9測試這個:

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
     <title>title</title> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> 
     <script> 
      $(document).ready(function() { 
    $(".link1").click(function(event){ 
     event.preventDefault(); 
     var url =$(this).attr("href"); 

     $('#right-pane').load(url, function(data) { 
     console.log(data); 
    }); 
     console.log(url); 
    }); 
}); 
     </script> 
    </head> 
    <body> 
     <div id="layer5" class="style2" style="position: absolute; width: 79px; height: 17px; z-index: 1; left: 11px; top: 15px"><a href="test2.html" class="link1">item 1</a></div> 
     <div id="right-pane" style="position: absolute; width: 988px; height: 649px; z-index: 2; left: 193px; top: 4px"></div> 
    </body> 
</html> 
+0

嗨金,感謝您的代碼,但每當我點擊超鏈接它不打開我當前頁面的div部分,它打開頁面「another.jsp」本身。 – Ars 2012-03-15 13:11:50

+0

@Ars再次看到我的更新 – Kimtho6 2012-03-15 13:15:01

+0

同樣的輸出,我應該發佈整個代碼? – Ars 2012-03-15 13:20:47

相關問題