简体   繁体   English

如何在选择HTML textarea内容时防止字符位置变化

[英]How to prevent the change of character position on selecting the content of html textarea

I've created a textarea, and counting its characters, when it reaches multiple of 160 increment the message count, and on moving the cursor it will show the character position and the message number properly. 我创建了一个文本区域,并对其字符进行计数,当它达到160的倍数时,将增加消息计数,并且在移动光标时它将正确显示字符位置和消息编号。 but on selecting the content it will display the message count as 0 and 0 remaining character , how to solve this, i'm trying to set the values as last character on selecting the content. 但是在选择内容时,它将显示消息计数为0和0个剩余字符 ,如何解决此问题,我正在尝试将值设置为选择内容时的最后一个字符。

Here is the working example of what I've tried : http://jsfiddle.net/F6CZs/1/ 这是我尝试过的工作示例: http : //jsfiddle.net/F6CZs/1/

Any guidance and help is appreciated..! 任何指导和帮助表示赞赏。 Here is the actual values : 这是实际值:

在此处输入图片说明

Here comes the change of values on selecting the content : 这是选择内容时值的更改: 在此处输入图片说明

我知道这不是“ keyup”,应该只是

 $(id).bind("keydown click", function () {

Try this. 尝试这个。

http://jsfiddle.net/U9vSF/1/ http://jsfiddle.net/U9vSF/1/

Not sure what you were trying to achieve with the, "# Message(s)" part of the counter. 不确定您要使用计数器的“#消息”部分来实现什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM