本文介绍了等待新行和计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的函式看起来像这样
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>更多推荐
等待新行和计数
发布评论