当您单击链接时,它会加载正确的文件,但如果您在#right 并向下滚动然后单击不同的链接,它将不会加载到顶部,您必须滚动到顶部。当您单击任何链接时,有关如何使其加载到#right 顶部的任何想法?
<script type="text/javascript" src="jquery-1.8.1.min.js"></script>
<style type="text/css">
#left,#right{
width:500px;
height:100px;
overflow: scroll;
overflow-x:hidden;
float:left;
}
</style>
<div id="left">
<ul>
<li><a class="page" id="one" href="one.html">One</a></li>
<li><a class="page" id="two" href="two.html">Two</a></li>
<li><a class="page" id="three" href="three.html">Three</a></li>
<li><a class="page" href="#">lskf</a></li>
</ul>
</div>
<div id="right"></div>
<script type="text/javascript">
$(document).ready(function(){
$('.page').click(function(e){
e.preventDefault();
var pg = $(this).attr('id');
var toLoad = $(this).attr('href');
var goin = $('#right').load(toLoad);
switch (pg){
case 'one':
goin;
break;
case 'two':
goin;
break;
case 'three':
goin;
break;
default: $('#right').load('test.html');
break;
}
});
});
</script>