duanba4942 2012-09-13 08:40
浏览 164
已采纳

使用onkeyup JS事件检查输入的值是否唯一

I am validating a field called client code for uniqueness...

I have used onkeyup JS event for this purpose. But its not working fine when i type the keys very fast. On this

onkeyup event

i am sending an ajax request to check whether the entered data already exists in the table or not.

Pls help if there is any alternative..

  • 写回答

3条回答 默认 最新

  • dongruo4601 2012-09-13 08:56
    关注

    Your question is quite vague in terms of the actual issue that you seem to be facing. But what I derive from it is that you are firing too many requests as you suggest rapid key presses!


    As you would know, Ajax is like a normal page request, just done async, so it is bound by the same network latency, throughput and round trip constraints.

    A clean way to achieve the functionality you need is to use a technique called throttling. One of the best js plugin for this purpose is located here: http://benalman.com/projects/jquery-throttle-debounce-plugin/ It basically allows you to rate-limit your requests to the server, thus not choking the resources and providing a smooth UI.


    Also, unless you wish to trap certain special keys like <kbd>ESC</kbd>, I would suggest using keypress or keydown events. Can't remember the specific reasoning for it, but just a suggestion.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?