javascript開發(fā)購物車項(xiàng)目介紹
本課程以開發(fā) 《javascript開發(fā)購物車》做為課程項(xiàng)目實(shí)例,為大家講解開發(fā) 《javascript開發(fā)購物車》的思路,以及開發(fā)《javascript開發(fā)購物車》如何編寫代碼實(shí)現(xiàn)邏輯等。
本次教程所開發(fā) 的功能如下:
點(diǎn)擊加減->實(shí)現(xiàn)加減的功能->實(shí)現(xiàn)總價(jià)等于單價(jià)與數(shù)量之和
我們來看下流程圖
購物車加減 效果圖如下:
當(dāng)點(diǎn)擊加的時(shí)候,數(shù)字是一直加的,減號是可以一直減的,但是減的值為0時(shí),值為1,如果輸入中文或英文,會(huì)有提示信息,然后值默認(rèn)為1
看下面的代碼:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>購物車加減</title> <style type="text/css"> a{ text-decoration: none;display:block;width:30px;height:30px; background:#eee;line-height:30px;font-weight:bolder; } .body{width:500px;height:300px;background:#ccc;margin:0 auto;text-align:center;padding:80px;} #a1{float:left;margin-right:20px;margin-top:2px;text-align:center;} form{float:left;} form input{width:40px;height:30px;border:1px solid #eee;text-align:center;} #a2{float:left;margin-left:20px;margin-top:2px;text-align:center;} </style> </head> <body> <div> <a href="#" id="a1">-</a> <form> <input type= "text" value="1" id='id'> </form> <a href="#" id="a2">+</a> </div> </body> </html>
以上我們就把頁面的樣子已經(jīng)做出來了