<html>
<body>
<div id="div1">
</div>
<script type="text/javascript">
function FormatDiv(curPage)
{
var html = "";
if(curPage<5) //如果点击的页数小于5,就实现 1 2 3 4 5
{
for(var i=1;i<=5;i++)
{
html += '<span onclick=FormatDiv(this.innerText)>'+i+"</span> ";
}
}
else //如果点击的页数大于5,就显示 curPage-2 curPage-1 curPage curPage+1 curPage+2
{
for(var j=(parseInt(curPage)-2);j<=(parseInt(curPage)+2);j++)
{
html += '<span onclick=FormatDiv(this.innerText)>'+j+"</span> ";
}
}
alert(html)
document.getElementById('div1').innerHTML = html;
}
window.onload = function(){
FormatDiv(1); //初始选择的是第一页
}
</script>
</body>
</html>
<body>
<div id="div1">
</div>
<script type="text/javascript">
function FormatDiv(curPage)
{
var html = "";
if(curPage<5) //如果点击的页数小于5,就实现 1 2 3 4 5
{
for(var i=1;i<=5;i++)
{
html += '<span onclick=FormatDiv(this.innerText)>'+i+"</span> ";
}
}
else //如果点击的页数大于5,就显示 curPage-2 curPage-1 curPage curPage+1 curPage+2
{
for(var j=(parseInt(curPage)-2);j<=(parseInt(curPage)+2);j++)
{
html += '<span onclick=FormatDiv(this.innerText)>'+j+"</span> ";
}
}
alert(html)
document.getElementById('div1').innerHTML = html;
}
window.onload = function(){
FormatDiv(1); //初始选择的是第一页
}
</script>
</body>
</html>
解决方案 »
- (急)请问这种关于div加载的代码怎么写?
- jquery事件问题!!对象 click和document click冲突问题
- 【分享】JavaScript Cube 1.6 发布
- js窗口获取父窗口控件的问题
- var oPopup=window.createPopup();在Firefox下的创建问题
- 如何对动态创建出来的DIV层添加鼠标事件?
- 拖动FrameSet的分割条,调整frame大小时触发的事件是什么?
- jquery基础教程第三章的练习题讨论
- 能否用JAVASCRIPT来判断一个<TEXTAREA>中,用户填写的字数
- 有谁知道rtsp://www。。。。。怎么下载嘛?
- 请教select下拉框的问题!
- 小问题,请大家帮忙解决?
<body>
<div id="div1">
</div>
<script type="text/javascript">
function FormatDiv(curPage)
{
var html = "";
if(curPage<5) //如果点击的页数小于5,就实现 1 2 3 4 5
{
for(var i=1;i<=5;i++)
{
html += '<span onclick=FormatDiv('+j+')>'+i+"</span>";
}
}
else //如果点击的页数大于5,就显示 curPage-2 curPage-1 curPage curPage+1 curPage+2
{
for(var j=(curPage-2);j<=(curPage+2);j++)
{
html += '<span onclick=FormatDiv('+j+')>'+j+"</span>";
}
}
document.getElementById('div1').innerHTML = html;
}
window.onload = function(){
FormatDiv(1); //初始选择的是第一页
}
</script>
</body>
</html>
<body>
<div id="div1">
</div>
<script type="text/javascript">
function FormatDiv(curPage)
{
var html = "";
if(curPage<5) //如果点击的页数小于5,就实现 1 2 3 4 5
{
for(var i=1;i<=5;i++)
{
html += '<span onclick=FormatDiv('+i+')>'+i+"</span>";
}
}
else //如果点击的页数大于5,就显示 curPage-2 curPage-1 curPage curPage+1 curPage+2
{
for(var j=(curPage-2);j<=(curPage+2);j++)
{
html += '<span onclick=FormatDiv('+j+')>'+j+"</span>";
}
}
document.getElementById('div1').innerHTML = html;
}
window.onload = function(){
FormatDiv(1); //初始选择的是第一页
}
</script>
</body>
</html>
<html>
<body>
<div id="div1">
</div>
<script type="text/javascript">
function FormatDiv(curPage)
{
curPage = parseInt(curPage);
var html = "";
if(curPage<=5) //如果点击的页数小于5,就实现 1 2 3 4 5
{
for(var i=1;i<=5;i++)
{
html += '<span onclick=FormatDiv(this.innerText)>'+i+"</span>";
}
}
else //如果点击的页数大于5,就显示 curPage-2 curPage-1 curPage curPage+1 curPage+2
{
for(var j=curPage-2;j<=curPage+2;j++)
{
html += '<span onclick=FormatDiv(this.innerText)>'+j+"</span>";
}
}
document.getElementById('div1').innerHTML = html;
}
window.onload = function(){
FormatDiv(7); //初始选择的是第一页
}
</script>
</body>
</html>