日期:2014-05-18  浏览次数:20490 次

一个javascript问题
以下代码第一次按向上是可以的,,,第二次就出错,,请问为何,,
如何解决这个问题!


HTML code
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="inc/all_func.asp"-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>广州讯荣办公设备有限公司</title>



<body>
<div style=" width:150px; height:300px; overflow:hidden">
<div id="up" style="position:relative; ">
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>低成本业绩增长战略</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>品牌年度推广方案</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>创智实效训练项目组合</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>样板市场服务</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>维达纸业品牌战略规划</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>然后突然</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>太让人忽然</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>广东人共同繁荣以后</td>
  </tr>
   <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>维达纸业品牌战略规划</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>然后突然</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>太让人忽然</td>
  </tr>
  
  <tr>
    <td><img src="" width="101" height="76"></td>
  </tr>
  <tr>
    <td>广东人共同繁荣以后</td>
  </tr>
</table>

</div>

</div>


<script language="javascript">

function up(){


document.getElementById("up").style.top=document.getElementById("up").style.top-50;

}
</script>

<input type="button" name="Submit" value="向上" onClick="up()">
</body>
</html>



------解决方案--------------------
是超出了吧.
JScript code

function up(){
try{
    var obj=document.getElementById("up")
        obj.style.top=obj.style.top-50; 
}
catch(e)
{
    obj.style.top=0;
}

}

------解决方案--------------------
JScript code

<script language="javascript">
var i=0;
function up(){
  i++;
  document.getElementById("up").style.top=-50*i;
  if (i<10){
  setTimeout(&