⑴ 求助js購物車代碼!要能點擊 添加按鈕 就直接在購物車顯示出來!可以修改數量!
<script language='javascript'>
function checkSum()
{
var sum = 0;
for(var i=0;i<document.form1.elements["writer"].length;i++)
{
if(document.form1.elements["writer"][i].checked)
{
sum = sum +parseInt(document.form1.elements["writer"][i].value);
}
}
totalprice.innerText = sum +" 元";
}
</script>
<form method=post name=form1>
<input type="checkbox" name=writer value="34" onclick="checkSum()">韓國耳飾(34元)<br>
<input type="checkbox" name=writer value="46" onclick="checkSum()">純銀吊墜tc34(46元)<br>
<input type="checkbox" name=writer value="30" onclick="checkSum()">黃鶯手鐲ta345(30元)<br>
<input type="checkbox" name=writer value="40" onclick="checkSum()">翡翠玉鐲1346(40元)<br>
<input type="checkbox" name=writer value="50" onclick="checkSum()">天涯耳飾1233(50元)<br>
<br>
總價為:<span id="totalprice">0 元</span>
</form>
⑵ 有沒有添加購物車的代碼 JavaScript 或者jquery 的都可以
添加購物車需要和伺服器端進行數據交互,前端主要是用js的ajax功能將產品的id或者其他信息提交給伺服器端,然後等伺服器端返回添加成功,再在頁面上的購物車中增加添加的商品。
⑶ jsp購物車代碼
//shopping.html
<html>
<head><title>shopping stor</title></head>
<body>
<form action="carts.jsp" target="post">
<br>
please select the item that you want to buy
<br>
<select name="item">
<option>book:old man and the sea
<option>x-box game machine
<option>mp3 player
<option>cce
<option>book:jsp programming
<option>cd "the endless love"
<option>dvd "gone with the wind"
</select>
<br>
<input type="submit" name="submit" value="add">
<input type="submit" name="submit" value="remove">
</form>
</body>
</html>
------------------------------------------------------------------
//carts.jsp
<%@page contentType="text/html;charset=ISO8859_1" %>
<html>
<jsp:useBean id="cart" scope="session" class="test.DummyCart"/>
<jsp:setProperty name="cart" property="*"/>
<%
cart.processRequest();
%>
<br>
<ol>
you have chosen these items:
<%
String []items=cart.getItems();
for(int i=0;i<items.length;i++)
{
%>
<li><%=items[i] %></li>
<%
}
%>
</ol>
<hr>
<%@include file="shopping.htm" %>
</html>
---------------------------------------------------------------------//DummyCart.java
package test;
import javax.servlet.http.*;
import java.util.Vector;
import java.util.Enumeration;
public class DummyCart
{
Vector v = new Vector();
String submit=null;
String item= null;
private void addItem(String name)
{
v.addElement(name);
}
private void removeItem(String name)
{
v.removeElement(name);
}
public void setItem(String s)
{
item=s;
}
public void setSubmit(String s)
{
submit=s;
}
public String[] getItems()
{
String []s=new String[v.size()];
v.Into(s);
return s;
}
public void processRequest()
{
if(submit==null)
addItem(item);
if(submit.equals("add"))
addItem(item);
else if (submit.equals("remove"))
removeItem(item);
reset();
}
private void reset()
{
submit=null;
item=null;
}
}
----------------------------------------------------------------------
上面是一個簡單的例子,功能都能實現,對網頁效果要求更漂亮些的可做一些修改。
⑷ 求一個JS代碼,就APP購物車的代碼,可以在html直接實現的
給樓主做了一個,JS實現商品計數的加和減,最少不能少於1,最多不大於99,代碼裡面有注釋,方面樓主查看和使用。
⑸ 想做一個簡單的購物車界面,非常簡單就行有代碼!用div+css做就可以
購物車外是可以的 但是核心最好還是用程序本來的核心如果自己寫,很有單獨
⑹ 用JavaScript代碼模擬購物車。
購物車挺復雜的,不是一句兩句能說清的,現在前端都用react,vue這類響應式框架做購物車,事半功倍。
⑺ 求html購物車代碼,,效果如圖顯示
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>修改訂單</title>
<styletype="text/css">
body{
font-size:13px;
line-height:25px;
}
table{
border-top:1pxsolid#333;
border-left:1pxsolid#333;
width:400px;
}
td{
border-right:1pxsolid#333;
border-bottom:1pxsolid#333;
text-align:center;
}
.title{
font-weight:bold;
background-color:#cccccc;
}
inputtext{
width:100px;
}
</style>
<scripttype="text/javascript">
functionaddRow(){
//行的長度
varrowlength=document.getElementById("order").rows.length;
//得到整個表格對象
varorder=document.getElementById("order").insertRow(rowlength-1);
order.id=rowlength-1;
//插入列
varcel1=order.insertCell(0).innerHTML="游戲光碟";
varcel2=order.insertCell(1).innerHTML="34";
varcel3=order.insertCell(2).innerHTML="¥58.40";
varcel4=order.insertCell(3).innerHTML="<inputtype="button"value="刪除"onclick="delRow('"+(rowlength-1)+"')"/>"+"<inputtype="button"value="修改"onclick="editRow('"+(rowlength-1)+"')"/>"
}
functiondelRow(qwe){
=document.getElementById(qwe).rowIndex;
document.getElementById("order").deleteRow(ewq);
}
functioneditRow(rowID){
varrow=document.getElementById(rowID);
varcel=row.cells;
vartext=cel[1].innerHTML;
cel[1].innerHTML="<inputtype='text'value='"+text+"'style='width:40px;'>"
cel[3].lastChild.value="確定";
cel[3].lastChild.setAttribute("onclick","update('"+rowID+"')");
}
functionupdate(qwe){
varrow=document.getElementById(qwe);
varcel=row.cells;
vartext=cel[1].lastChild.value;
cel[1].innerHTML=text;
cel[3].lastChild.value="修改";
cel[3].lastChild.setAttribute("onclick","editRow('"+qwe+"')");
}
/*
functionadd(){
vara=document.getElementById("order").rows.length;
varb=document.getElementById("order").insertRow(a-1);
varone1=b.insertCell(0).innerHTML="123";
}
*/
</script>
</head>
<body>
<tableborder="0"cellspacing="0"cellpadding="0"id="order">
<trclass="title">
<td>商品名稱</td>
<td>數量</td>
<td>價格</td>
<td>操作</td>
</tr>
<trid="1">
<td>防滑真皮休閑鞋</td>
<td>12</td>
<td>¥568.50</td>
<td><inputname="rowdel"type="button"value="刪除"onclick='delRow("1")'/>
<inputid="edit1"type="button"value="修改"onclick='editRow("1")'/></td>
</tr>
<tr>
<tdcolspan="4"style="height:30px;">
<inputname="addOrder"type="button"value="增加訂單"onclick="addRow()"/></td>
</tr>
</table>
</body>
</html>
這個是我原來上學的時候練習的代碼,練習的是基礎的jsDOM操作,不過建議以後用Jquery 比較方便 有什麼不懂得可以問我
⑻ 請問js購物車代碼加在哪才能實現當顧客看到加入購物車的按鈕,點擊後出現彈出框呢
加在當前頁面的<script>的一個方法中,你點擊按鈕觸發這個方法就行
⑼ 在HTML里用javascript做一個簡單購物車部分
給樓主做了一個,JS實現商品計數的加和減,最少不能少於1,最多不大於99,代碼裡面有注釋,方面樓主查看和使用。
⑽ 求用javascript編寫的簡易購物車小程序如圖所示:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtml2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
/*
*@author Caoshun
*@計算 合計費用
*/
function countMethod(){
var num=document.getElementById("num").value;
var unitPrice=document.getElementById("unitPrice").value;
var freight=document.getElementById("freight").value;
document.getElementById("result").value=parseFloat((num*unitPrice))+parseFloat(freight);
}
</script>
</head>
<body>
<table border="1" cellpadding="1" cellspacing="1" background="#red" style="text-align: center;">
<tr><td colspan="5" align="center">簡易購物車</td></tr>
<tr>
<td>商品名稱</td>
<td>數量(件)</td>
<td>單價(美元)</td>
<td>運費(美元)</td>
<td><input type="button" value="合計" onclick="countMethod();"></td>
</tr>
<tr>
<td>跑跑道具</td>
<td><input type="text" size="6" id="num"></td>
<td><input type="text" size="6" id="unitPrice"></td>
<td><input type="text" size="6" id="freight"></td>
<td><input type="text" size="6" id="result"></td>
</tr>
</table>
</body>
</html>