首页 > 解决方案 > 在 keyup children child 上检索新数据到 div

问题描述

我正在尝试检索由输入字段动态添加的数据值。但是这个值没有用 .on 更新

<div class="box" data-box="7532 7533 7534">
    <input type="number" class="number_box">
</div>

$(document).on('keyup', '.number_box ', ' .pdt-pn', function() {

  $box = $(this).val();
  
  console.log( $(this).closest('.box').data('box'));
  
  $boxplus = $(this).closest('.box').data('box') + $box;
  $(this).closest('.box').attr('data-box', $boxplus);
});

我的 console.log 总是检索相同的数字,但没有新值。请参阅小提琴https://jsfiddle.net/r4kqsjga/1/

我不明白!谢谢你的帮助

标签: keyup

解决方案


推荐阅读