代码改变世界

js实现购物车数量的自增与自减

2010-02-25 11:57  曾祥展  阅读(5543)  评论(0编辑  收藏

曾祥展   素材:btn_down btn_up

 

<script type="text/JavaScript">
function qtyUpdate(kind){
    var f = document.form1;
    var c = f.qty.value;
    if(kind == "up"){
        c++;
    }else if(kind == "down"){
        if(c > 1) c--;
    }
    f.qty.value = c;
}
</script>

<FORM  name=form1 >
<TABLE border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD rowSpan=2><INPUT value=2 readOnly size=5 name=qty></TD>
<TD rowSpan=2 width=3></TD>
<TD><A href="javascript:qtyUpdate('up')"><IMG src="btn_up.gif" width=11 height=8></A></TD>
</TR>
<TR>
<TD align=right><A href="javascript:qtyUpdate('down')"><IMG src="btn_down.gif" width=11 height=8></A></TD>
</TR>
</TBODY>
</TABLE>
</FORM>