等待新行和计数

编程入门 行业动态 更新时间:2024-10-19 21:26:05
本文介绍了等待新行和计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的函式看起来像这样

function count() { var value = ids.val(); return (value == '') ? 0 : value.split(/\r\n|\r|\n/).filter($.trim).map($.trim).length; }

有一个问题。我有autopost函数,每隔1秒检查 count()。

There is one problem. I have autopost function which checks for count() every 1 sec.

if(count() === 10){ ajaxpost! }

条形码读取器逐一输入数字:每次扫描后都会添加新行。

Barcode reader enters digits one by one: it adds new line after each scan.

如何修改此函数以等待新行和计数?

How to modify this function to wait for new line and count?

例如

8

函数必须返回0(当前在输入任何值后直接返回1)

Function must return 0 (currently it returns 1 directly after typing any value)

8 <newline>

函数必须返回1

推荐答案

您实际上可以修改条形码扫描仪,不给新行,但是您可以使用替换并删除新行。像

You can actually modify the barcode scanner to not give the new line, but else you can use the replace and remove the new lines. something like

myStr.replace(/[\r\n]/,'')

EDIT 让我更好地解释一下:

EDIT let me explain better:

return (value == '') ? 0 : value.split(/\r\n|\r|\n/).filter($.trim).map($.trim).replace(/[\r\n]/,'').length;

这将删除您没有的新行

8 <newline>

更多推荐

等待新行和计数

本文发布于:2023-10-26 23:41:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531685.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!