现在的位置: 首页 > 综合 > 正文

一个比较有趣的例子

2013年12月07日 ⁄ 综合 ⁄ 共 1392字 ⁄ 字号 评论关闭
<script language="javascript">
 function Qty_onClick(arg)
 {
  var theObj = document.getElementById("Qty")
  var amount = theObj.value;
  if(isNaN(parseInt(amount))){amount=0};
  if (amount<=0)//the MinAmount
  {
   alert("已达到最小数值0");//MinAmountReached
   theObj.value = 0+1; //the MinAmount+1
   theObj.focus();
   return;
  }//end if
  if (amount>=100)//the MaxAmount
  {
   alert("已达到最大数值100");//MaxAmountReached
   theObj.value = 100-1; //the MaxAmount-1
   theObj.focus();
   return;
  }//end if
  var sum = parseInt(amount) + parseInt(arg);
  if (sum > 0 && sum < 100)
  {
   theObj.value = sum;
  }//end if
 }
 </script>
<table border="0" cellspacing="0" cellpadding="0" style="border:1px solid #CCCCCC;">
<tr>
<td rowspan="3" style="border-right:1px solid #CCCCCC;">
        <input name="Qty" type="text" id="Qty" style="font-family:'Verdana';font-size:12px;text-align:right;border:none;" value='1' size=2 maxlength=2>
       </td>
       <td style="line-height:9px;">
        <a style="font-family: Webdings;font-size: 9px;line-height: 8px;text-decoration: none;" href="javascript:;" onClick="javascript:Qty_onClick(1);"><font face="Webdings">5</font></a>
       </td>
     </tr>
     <tr>
       <td height="1" bgcolor="#CCCCCC"></td>
     </tr>
     <tr>
       <td style="line-height:9px;">
        <a style="font-family: Webdings;font-size: 9px;line-height: 8px;text-decoration: none;" href="javascript:;" onClick="javascript:Qty_onClick(-1);"><font face="Webdings">6</font></a>
       </td>
     </tr>
</table>

抱歉!评论已关闭.