【问题标题】:Input text typing lags too much because of big number of events由于大量事件,输入文本输入滞后太多
【发布时间】:2015-11-28 12:30:51
【问题描述】:

我正在做一个应用程序,我的这个页面有 200 个输入文本框。几乎所有人都在 ready/input 上有一个事件,这是一个例子

function callpVol41l() {
  plan_vol_sc('plan_hrs_41l', 'prod_41n', 'plan_vol_41l');
}

$(document).
  on('ready input', callpVol41l).
  on('input', '#plan_hrs_41l,#prod_41n,#plan_vol_41l', callpVol41l);

我的问题是由于输入文本数量过多,当我输入其中任何一个时,都会有一点延迟。有什么解决办法吗? (不仅是谷歌浏览器,我知道这个问题,即使是 IE 也有一点滞后.. 反正比 chrome 少。)

【问题讨论】:

  • plan_vol_sc 是做什么的?您是否检查过延迟来自何处的调试器工具(例如性能分析)?
  • plan_vol_sc 是一个函数,它从 id=prod_41n 的输入文本中获取值,并将其与来自 id plan_hrs_41l 的输入文本中的值相除,并将结果写入 id 为 plan_vol_41l 的输入文本中,并且不,我没有检查调试器工具..
  • jQuery 非常低效。如果输入在表单中,那么您可以使用 POJS 和属性访问,而不是构建 jQuery 对象并调用其方法。提供一个最小的工作示例。

标签: javascript events input types lag


【解决方案1】:

您将所有内容直接附加到文档中。也许只是选择不同的输入?

向您的输入添加一个类,并向输入添加一个onchange 事件。

<input class="something">
$(document).ready(function(){
  $input = $('input.something');
  $input.on('change', function(){
    var myValue = $(this).val(); // get value
    callpVol41l(myValue); // run the function you want to happen.
  });
}

【讨论】:

  • 好的,但我的问题是我必须这样做更少或更多.. 150 次.. 我不得不将它直接附加到文档,因为我遇到了动态自动填充输入的问题..没有这个函数就不会触发..这就是我必须这样做的原因..
猜你喜欢
  • 1970-01-01
  • 2021-09-07
  • 2021-06-04
  • 2019-10-31
  • 2013-11-06
  • 1970-01-01
  • 1970-01-01
  • 2010-12-14
  • 2017-10-10
相关资源
最近更新 更多