当值超过字符最大值时如何更改文本框的颜色
我有一个宽度不同的文本框,假设文本框中可见字符的最大数量是 10。现在我希望当用户输入超过 10 个字符时,文本框的颜色会发生变化。
要检查所有值,用户必须将鼠标悬停在其上。 那么如何根据给定条件更改文本框的颜色。
谢谢 或者 请告诉我如何查找文本框中没有可见字符
I have a textboxes whose width varies, let us suppose that the maximum no of visible character in a textbox are 10. now I want that when the user enters more than 10 char the color of the textbox is changed.
To check all the values the user has to hover his mouse on it.
so how do I change color of textbox based on the given condition.
Thanks
or
Please tell me how to find no of visible characters in a textbox
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您熟悉 jQuery,可以通过以下方法解决:
html
(jquery)javascript
我真的不知道“没有可见”字符。
If you are familiar with jQuery it can be solved by the following:
html
(jquery)javascript
I don't really know about the "no of visible" characters.
您必须使用 JavaScript 来执行此操作。
检查文本框中字符串的长度。如果长度> 10.然后更改文本框的背景颜色。
You'll have to use javascript to do this.
Check the length of the the string in the textbox. If length > 10 then change the background color of the textbox.
您可以使用 JavaScript 来做到这一点。
不过还有一个问题!
您想将空格算作字符吗?或者你只想计算没有空间的字符?
希望这有帮助!
You can do that with Javascript.
One question though!
Do you want to count spaces as char? or do you want to only count char with out space?
Hope this helps!
您需要做一些研究才能在用户键入时动态更改计数,但这是一个很好的开始方法:
打开一个新的文本文件并复制上述代码并使用 HTML 扩展名保存,然后使用在浏览器中,只需将鼠标指针悬停在文本区域上,您就会注意到
文本随着文本区域控件内的字符数而变化。
You need to do a little bit of research to dynamically change the count as the user is typing, but here is a good way to start:
Open a new text file and copy the above code and save it with an HTML extension then open it with the browser, and just hover the mouse pointer over the textarea, you will notice that a
text changes with the count of the characters inside the textarea control.