代码如下:
<script type="text/javascript">
function sub(){
var num=parseInt(document.getElementById("purchasenum").value);
if(num>1){
document.getElementById("purchasenum").value=--num;
}
}
function add(){
var num=parseInt(document.getElementById("purchasenum").value);
if(num<100){
document.getElementById("purchasenum").value=++num;
}
}
function selflog_show(id){
var num=document.getElementById("purchasenum").value;
J.dialog.get({id:'haoyue_creat',title:'购物成功',width: 600,height:400, link:'<%=path%>/servlet/CartServlet?id='+id+'&num='+num+'CartAction=add',cover:true});
}
</script>
body中的代码:
<h2><%=i.getName()%></h2>
<p>商品ID=<%=i.getId()%></p>
<span>
<span>¥<%=i.getPrice()%></span><br><br><br>
<!-- <label>数量:</label> -->
数量:
<span id="sub" onclick="sub();">-</span>
<span id="add" onclick="add();">+</span>
<input type="text" name="purchasenum" id="purchasenum" value="1" />
<a href="javaScript:selflog_show(<%=i.getId()%>)">
<button type="button" class="btn btn-fefault cart">
<i class="fa fa-shopping-cart"></i>
加入购物车
</button>
</a>
<!--
<button type="button" class="btn btn-fefault cart">
<i class="fa fa-shopping-cart"></i>
加入购物车
</button>
-->
</span>
<p><b>库存:</b> <%=i.getStock()%></p>
<p><b>产地:</b> <%=i.getCity()%> </p>
<%} %>
出现的错误如下:
一旦点击“加入购物车” 出现:
Goods_Details.jsp?id=1:58 Uncaught ReferenceError: J is not defined
at selflog_show (Goods_Details.jsp?id=1:58)
at :1:1
bootstrap.min.js:7 Uncaught TypeError: Cannot read property 'offsetWidth' of undefined
at b.slide (bootstrap.min.js:7)
at b.next (bootstrap.min.js:7)
at i (jquery.js:4)
拜托各位啦