在 jQuery 中使用新行

发布于 2025-01-06 13:38:59 字数 186 浏览 2 评论 0原文

下面的代码从文本框中获取文本,用“,”分割,然后如果字数超过10,则通过ajax将其发送到php。我设计此代码是为了与条形码阅读器(setinterval...等)一起使用。现在的问题是,无法设置条形码阅读器在每次扫描条形码后留下逗号。它添加了换行符。

所以我们可以说 ids.val();是换行符分隔的单词。如何将它们转换为逗号分隔的单词?

The code below gets text from textbox,splits by ",", then if words count more than 10 sends it to php via ajax. I designed this code to work with barcode reader (setinterval... etc). Now the problem is, can't set barcode reader to leave comma after each scanned barcode. It adds line break.

So lets say ids.val(); is line break seperated words. How do I convert them into comma seperated words?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有 2025-01-13 13:38:59

使用

.indexOf("\n")

and

.split("\n")

代替逗号版本!请注意,您可能希望使用 \n\r\n 进行更改,因为某些浏览器将换行符实现为前者,而另一些浏览器则实现为后者。

如果您想将所有换行符转换为逗号,请使用

commaSeparatedString = newlineSeparatedString.replace(/\\n/g, ",");

Use

.indexOf("\n")

and

.split("\n")

instead of the comma-versions! Note that you might want to vary with \n and \r\n as some browsers implement a newline character as the former and some as the latter.

If you would want to convert all newlines to comma's, then use

commaSeparatedString = newlineSeparatedString.replace(/\\n/g, ",");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文