首页 > Web开发 > 详细

JS在页面根据数量改变总价及按钮进行格式验证

时间:2018-07-23 10:10:16      阅读:238      评论:0      收藏:0      [点我收藏+]

分两部分,第一部分是在页面上,根据数量的input标签内容,动态更新总价标签的内容,代码如下:

<script type="text/javascript">
    $(document).ready(function () {
        $("#iquantity").bind(‘input propertychange‘, function () {
            var quantity = $("#iquantity").val();
            var price = 49;
            var total = price * quantity;
            $("#atotal").text(total);
            });
        });
</script>

另一部分是按钮的验证,代码如下:

 1 <script type="text/javascript">
 2     $(document).ready(function () {
 3         $("#btSave").click(function () {
 4             if ($("#iquantity").val() == "") {
 5                 alert("请填写购买数量\rPlease fill in the Quantity");
 6                 return false;
 7             }
 8             var zz = /^[1-9]\d*$/;
 9             var qq = $("#iquantity").val();
10             if (!zz.test(qq)) {
11                 alert("请正确填写购买数量,格式为非零的正整数\rPlease fill in the correct format for the Quantity.A positive integer in the form of nonzero.");
12                 return false;
13             }
14             $("#btSave").hide();
15             var words = "请稍后...";
16             $("#F").html(words);//F为一个span标签
17             return true;
18         });
19     });
20 </script>    

 

JS在页面根据数量改变总价及按钮进行格式验证

原文:https://www.cnblogs.com/Lvkang/p/9353012.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!