我的功能似乎沒有正確執行。哪裏不對?我已經花了5個小時試圖讓這個dang功能起作用。最終我會把照片上的鏈接。我的javascript功能似乎沒有工作。我不明白爲什麼
<html>
<head>
<script type="text/javascript">
var pagenumber=1;
function increase()
{
if(pagenumber == 1)
{
return
}
pagenumber++;
}
function decrease()
{
if(pagenumber == 5)
{
return
}
pagenumber--;
}
function slider() {
if(pagenumber == 1)
{
document.getElementById('pg1').style.display='inline';
document.getElementById('pg2').style.display='none';
document.getElementById('down').style.cursor='not-allowed';
document.getElementById('down').style.background-position='top';
}
if(pagenumber == 2)
{
document.getElementById('pg1').style.display='h';
document.getElementById('pg3').style.display='none';
document.getElementById('pg2').style.display='inline';
document.getElementById('down').style.cursor='pointer';
document.getElementById('down').style.background-position='bottom';
}
if(pagenumber == 3)
{
document.getElementById('pg2').style.display='none';
document.getElementById('pg4').style.display='none';
document.getElementById('pg3').style.display='inline';
}
if(pagenumber == 4)
{
document.getElementById('pg3').style.display='none';
document.getElementById('pg5').style.display='none';
document.getElementById('pg4').style.display='inline';
document.getElementById('down').style.cursor='pointer';
document.getElementById('up').style.background-position='top';
}
if(pagenumber == 5)
{
document.getElementById('pg4').style.display='none';
document.getElementById('pg5').style.display='inline';
document.getElementById('up').style.cursor='not-allowed';
document.getElementById('up').style.background-position='bottom';
}
}
</script>
</head>
<body height="183px" bgcolor="#F3F3F3" style="width:279px">
<div id="down" style="float:left;margin-top:29px;height:27px;width:15px;display:block;cursor:pointer;background:url('website/arrow_left.png') no-repeat top left;background-repeat:no-repeat;background-position:top">
<img src="website/pixel.png" width="15px" height="30px" onclick="decrease()" onclick="slider()">
</div>
<div id="up" style="float:right;margin-top:29px;height:27px;width:15px;display:block;cursor:pointer;background:url('website/arrow_right.png') no-repeat top left;background-repeat:no-repeat;background-position:top">
<img src="website/pixel.png" width="15px" height="30px" onclick="increase()" onclick="slider()">
</div>
<table style="background:url('website/arrow_middle.png') no-repeat center" align="center">
<tr id="pg1" style="display:inline">
<td style="padding-left:25px; padding-right:25px">
<a href="google.com">
<img src="website/oil.jpg" width="75px" height="75px">
</a>
</td>
<td style="padding-right:25px">
<a href="amazon.com">
<img src="website/gas.jpg" width="75px" height="75px">
</a>
</td>
</tr>
<tr id="pg2" style="display:none">
<td style="padding-left:25px; padding-right:25px">
<a href="google.com">
<img src="website/nuclear.jpg" width="75px" height="75px">
</a>
</td>
<td style="padding-right:25px">
<a href="amazon.com">
<img src="website/solar.jpg" width="75px" height="75px">
</a>
</td>
</tr>
<tr id="pg3" style="display:none">
<td style="padding-left:25px; padding-right:25px">
<a href="google.com">
<img src="website/wind.jpg" width="75px" height="75px">
</a>
</td>
<td style="padding-right:25px">
<a href="amazon.com">
<img src="website/hydro.jpg" width="75px" height="75px">
</a>
</td>
</tr>
<tr id="pg4" style="display:none">
<td style="padding-left:25px; padding-right:25px">
<a href="google.com">
<img src="website/electric.jpg" width="75px" height="75px">
</a>
</td>
<td style="padding-right:25px">
<a href="amazon.com">
<img src="website/thermal.jpg" width="75px" height="75px">
</a>
</td>
</tr>
<tr id="pg5" style="display:none">
<td style="padding-left:25px; padding-right:25px">
<a href="google.com">
<img src="website/mining.jpg" width="75px" height="75px">
</a>
</td>
<td style="padding-right:25px">
<a href="amazon.com">
<img src="website/transversal.jpg" width="75px" height="75px">
</a>
</td>
</tr>
</table>
</body>
</html>
只是一個提示:你在做'if(x == 1)if(x == 2)etc'。更好的方法是使用'if(x == 1)else if(x == 2)etc',最好的方法是使用[switch](https://developer.mozilla.org/en-US/文檔/網絡/的JavaScript /參考/語句/開關)。 – Itay
你應該在jsfiddle中得到一個工作示例。建立鏈接並儘可能使其工作,並且人們將更有能力幫助您解決問題。我已經在這裏爲你啓動了一個: http://jsfiddle.net/loweryaustin/3hTTN/ – Austin