<div class="caigou">
<form action="" method="post">
<div class="num_box">
<a id="sub">-</a>
<input id="num" class="num" name="num" value="1">
<a id="add">+</a>
</div>
</form>
<div id="zong">
<b id="zongjia">{$xianjia}</b>元
</div>
</div>
<script>
var b_num=document.getElementById('num');
var b_sub=document.getElementById('sub');
var b_add=document.getElementById('add'); var b_zongjia=document.getElementById('zongjia');
var b_danjia=parseInt(b_zongjia.innerHTML);
//只能是数字
b_num.onkeyup=function(){this.value=this.value.replace(/[^0-9]/g,''); jiesuan()}
b_num.onafterpaste=function(){this.value=parseInt(this.value.replace(/[^0-9]/g,''));jiesuan()}
//禁止选中
b_sub.onselectstart=function(){ return false;}
b_add.onselectstart=function(){ return false;}
//加减计算
b_sub.onclick=function(){
if(b_num.value<=1){ return false}
b_num.value = parseInt(b_num.value)-1;
jiesuan()
}
b_add.onclick=function(){
b_num.value = parseInt(b_num.value)+1;
jiesuan()
} function jiesuan(){
if(b_num.value==""){
b_num.value=0;
b_zongjia.innerHTML=0; return}
b_zongjia.innerHTML= parseInt(b_num.value)*b_danjia;
}
//禁止回车
b_num.onfocus=function(){ window.onkeydown=function(event){
if(event.keyCode==13||event.keyCode==109||event.keyCode==107){return false;} }
} b_num.onblue=function(){
window.onkeydown=function(){};
} </script>

购物车相关 js的更多相关文章

  1. 当页面提交时,执行相关JS函数检查输入是否合法

    当页面提交时,执行相关JS函数检查输入是否合法 关键代码 <form action="tj.php" method="post" onSubmit=&qu ...

  2. 前端相关js

    1. mailchimp.js: 通过电子邮件订阅 RSS 的在线工具 2. ga.js:google推出的用来统计网站信息的一个java脚本.可以在GoogleAnalytics获得网站的统计和追踪 ...

  3. jquery属性的相关js实现方法

    有些公司手机网站开发不用第三方的jquery或者zeptio,直接用原生的javascript.原生javascript功能是蛮强大的,只不过部分属性不支持IE8以下浏览器.下面对jquery相关方法 ...

  4. offsetWidth相关js属性

    js你真的了解offsetWidth吗   offsetWidth是什么? 答:它可以获取物体宽度的数值 那么就只是这样吗! html部分 <div id="div1"> ...

  5. 最常用的~正则表达式-相关js函数知识简洁分享【新手推荐】

    一.正则表达式的创建 JS正则的创建有两种方式: new RegExp() 和 直接字面量. //使用RegExp对象创建 varregObj =newRegExp("(^\s+)|(\s+ ...

  6. mvc 相关js

    http://modernizr.com/ https://github.com/Modernizr/Modernizr/wiki 主要看下Polyfills 用于html5,用于一些老ie,fire ...

  7. 微博输入相关js 代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. 微信支付相关js

    import $ from "jquery" /*支付功能开始*/let ip="";let nonceStr;let appId;let mchId;let ...

  9. python 全栈开发,Day52(关于DOM操作的相关案例,JS中的面向对象,定时器,BOM,client、offset、scroll系列)

    昨日作业讲解: 京东购物车 京东购物车效果: 实现原理: 用2个盒子,就可以完整效果. 先让上面的小盒子向下移动1px,此时就出现了压盖效果.小盒子设置z-index压盖大盒子,将小盒子的下边框去掉, ...

随机推荐

  1. Windows 上如何安装Sqlite

    对SQLite文明已久,却是从来没使用过,今天就来安装试用下. 一.安装 下载地址:http://www.sqlite.org/download.html 将Precompiled Binaries ...

  2. [LeetCode] Minimum Height Trees 最小高度树

    For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...

  3. [LeetCode] Inorder Successor in BST 二叉搜索树中的中序后继节点

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST. No ...

  4. [LeetCode] Merge Two Sorted Lists 混合插入有序链表

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  5. Gulp 入门

    1. 安装 Node 环境 参考 http://www.cnblogs.com/zichi/p/4627728.html,注意一起安装 npm 工具,并把路径保存到环境变量中(安装过程中会有提醒) 安 ...

  6. 如何在HoloLens中创建一个2D的Hello World程序

    注:本文提及到的代码示例下载地址 > How to build an "Hello World" 2D app in HololLens. HoloLens 是微软的一款MR ...

  7. 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法

    原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者jdk并配置好环境变量.(2)copy一个jvm.dll放在该目录下. 原因2:eclipse的版本与jre或者jdk版本不一致 ...

  8. bash的管道符与重定向

    管道符"|"可以用来将前面的程序的标准输出stdout(=1)重定向到后一个程序的stdin(=0),但是忽略了stderr. 在bash中使用2>&1 可以表示将s ...

  9. destoon : 后台无法登录问题解决

    经常有朋友在destoon搬家的时候 , 数据还原之后 , 会出现后台无法登录的情况 . 具体表现为后台帐号密码输入后点击确定 , 页面刷新 .并没有跳转到相应后台页面 . 但是如果帐号密码输入错误 ...

  10. ubuntu安全卸载移动硬盘(safely remove)

    移动磁盘不能安全卸载.在网上找到的资料如下: sudo apt-get install udisks sudo umount /dev/sdb1 sudo udisksctl power-off -b ...