检测并删除输入框溢出
我有一个带有属性的输入框
溢出:隐藏;
我还使用 javascript 来停止输入文本,以便它不会溢出,但是如果用户设法将文本插入到已经满的文本框中,我希望能够删除任何溢出。
无论如何,javascript 中是否有检测 texbox 何时隐藏溢出的方法?并删除它
谢谢
I have a input box with the attribute
overflow:hidden;
I have also used javascript to stopped text being entered so that it cant overflow however I would like to be able to remove any overflow if the user manages to insert text into an already full textbox.
Is there anyway in javascript to detect when a texbox has hidden overflow? and remove it
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你想使用 javascript 主动修剪输入框中的文本,你可以尝试:
这段代码不太漂亮,但它显示了你可以做什么,每次文本框中的文本变得很长时,函数都会修剪文本(它是比你要求的强一点,但你可以通过将事件更改为“onblur”来减弱它)。然而,etc 所建议的通常应该有效。
if you want to activly trim the text in the input box using javascript you can try:
this code is not pretty but it shows what you can do, every time the text in the text box gets to long the function trims the text(its a little stronger than what you asked but you can tone it down by changing the event to "onblur"). However, what etc suggested should usually work.
您是否尝试设置可以输入的最大字符数?如果是这样:
Are you trying to set the max number of characters that can be entered? If so: