dongshi9526 2015-04-07 10:10
浏览 62

将两个文本框内部循环并在第三个文本框中显示结果

This code will result for 10 lines of textbox1, textbox2, and textbox3. If I enter value in first line of textbox which is in loop1. for example 1 and 3 it will multiply and result is 3 . but then it will display the result in all loop. How can i make it only in loop1.?

Example

        QTY    PRICE   AMOUNT

line1    1        2      3
line2                    3
line3                    3
line4                    3
line5                    3
line6                    3
line7                    3
line8                    3
line9                    3
line10                   3

PHP HTML CODE

<?php for($x=1; $x<=10; $x++){?>
<tr> 
    <td><input type="text" name="qty<?=$x;?>" class="qty form-control" size="6"/></td>
    <td><input type="text" name="price<?=$x;?>" class="price form-control" /></td>
    <td><input type="text" name="amount<?=$x;?>" class="amount form-control"></td>
</tr>
<?php } ?>

JS CODE

<script>
    $(".price,.qty").keyup(function () {
      $('.amount').val($('.qty').val() * $('.price').val());
    });
</script>
  • 写回答

3条回答 默认 最新

  • dozabg1616 2015-04-07 10:15
    关注

    this will be much easy if you write separate for each event try this,

      <script>
     $(document).ready(function(){
            $(".qty").keyup(function () {
            $(this).closest('tr').find('.amount').val($(this).val() *    $(this).closest('tr').find('.price').val());
        });    
    
         $(".price").keyup(function () {
          $(this).closest('tr').find('.amount').val($(this).closest('tr').find('.qty').val() * $(this).val());
        }); 
    }); 
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程