jqEasy Counter (jquery) - 需要有“返回”算作 2 个字符 - 怎么算?
我正在使用 jqEasy 计数器对文本区域中的字符进行倒计时。 http://web.archive.org /web/20150317063551/http://www.jqeasy.com/jquery-character-counter
但在我们的实现中——数据库计算返回键计为 2 个字符,而计数器仅将其计为 1 个。基本上,表单提交会获取返回值并将其设置为“/n”或其他内容。
有人建议我如何修改此代码以使返回键在计数器中注册 2 个字符吗?
谢谢!
I'm using the jqEasy counter to countdown characters in a text area.
http://web.archive.org/web/20150317063551/http://www.jqeasy.com/jquery-character-counter
In our implementation though--the database counts a return key as 2 characters while the counter only counts it as one. Basically the form submission takes the returns and makes them "/n" or something.
Does anyone have a recommendation on how I could modify this code to make the return key register 2 characters in the counter?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,除非您更改插件的代码,否则您不能。现在输入的长度是按照插件的这种方式(第 56 行)计算的:
改变它:
你应该做的是迭代 val 并找出按回车键的次数,然后对该值求和到了长度。不幸的是,我不知道如何找出字符串中的“返回”
编辑 - 这就是你可以做的:
这应该可行,看看小提琴 http://jsfiddle.net/D27gs/2/
记住将其附加到 keyup 事件,否则它将不起作用
No you can't unless you change the code of the plugin. Right now the length of the input is calculated in this way (line 56) of the plugin:
Change it this way:
What you sholud do is iterate over val and find out how many times the return key has been pressed and then sum that value to the lenght. Unfortunately i don't know how to find out "returns" in a string
EDIT - This is what you can do:
This should work, look at the fiddle http://jsfiddle.net/D27gs/2/
remember to attach this to the keyup event or it won't work