doujiang1832 2019-05-11 22:53
浏览 97

如何设置子元素的最小和最大数据

Hello I can't set min and maximum value from database.

Actually I want to make dynamic it through PHP. In the back-end there should be two fields first minimum and second one with maximum. In maximum field, I can set maximum and in minimum field I can set, and call it through PHP in my coding.

Is that something can we do? here's coding.

<html>
<body>
<head>
</head>

<?php

  echo '
    <script>
    $(document).on("change", ".qty1", function() {
        var sum = 0;
        $(".qty1").each(function(){
            sum += +$(this).val();
        });
        $(".total").val(sum);
    });

    </script>';

$maxnum = 7;
if(num > $maxnum){
echo "<script>alert('Yes it is big');</script>";
}


?>
    <input type="text" class="qty1" value="" />
        <input type="text" class="qty1" value="" />
        <input type="text" class="qty1" value="" />
        <input type="text" class="qty1" value="" />
        <input type="text" class="qty1" value="" />
        <input type="text" class="qty1" value="" />
        <input type="text" class="total" value="" />
        </body></html>

how can I use php with jquery or should I change my coding. I don't know how I can change my coding is there any idea please?

  • 写回答

1条回答 默认 最新

  • duanliaogui4133 2019-05-12 03:44
    关注

    you could put all values into an array and then get the min/max

        $(document).on("change", ".qty1", function() {
            var arr = [];
            var sum = 0;
            $(".qty1").each(function(){
                    arr.push($(this).val());
                    sum += +$(this).val();
            });
            $(".total").val(sum);
            $("#min").val(Math.min.apply(Math, arr));
            $("#max").val(Math.max.apply(Math, arr));
    
       });
    

    Working fiddle https://jsfiddle.net/w47fLjcu/

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?