分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

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

发布时间:2023-09-06 02:05责任编辑:彭小芳关键词:暂无标签

分两部分,第一部分是在页面上,根据数量的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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved