前端和后端两种方法实现价格的增加与减少

第一种方法
前端方法 实现电机事件 获取价格的值
因为文本框的值是text类型 所以要转int 用parseInt

<script type="text/javascript">
 function zz(){
 var p = $("[name='price']").val()
 $("[name='price']").val(parseInt(p)+100);
 }
 </script>
<body>
<input type="text" name="price">
</body>

第二种方法 在后端修改价格的值 通过ajax

<script type="text/javascript">
var p = $("[name='price']").val()
if(p >= 0 && p<= 3200){
  $.ajax({
  async:false,
   url:"<%=path%>/toupdd.do",
   data:{"mid":mid},
   dataType:"json",
   type:"post",
   success:function(obj){
   alert("涨价成功")
    location="<%=path%>/look.do?mid="+mid; 成功后需要带着id跳回页面
     }
  })
 }else{
  alert("价格不能 超过3300块")
  
  
 } 
 <body>
 <input type="text" name="price">
 </body>
mapper.xml中 
<update id="toupd" parameterType="int">
update mobile set price = price- 100 where mid=#{mid}
</update>


 

猜你喜欢

转载自blog.csdn.net/L__MY/article/details/88926852