我该如何解决这个 onclick-onblur 问题?
我有一个表格。其中我有一个文本区域,单击时会展开。 但有一个小问题: 当用户尝试提交表单(单击提交按钮)时,文本区域会跳回其正常大小。这是因为它使用了 onblur 函数。我想消除这种尴尬,因为用户必须单击提交按钮两次才能提交表单。
我应该怎么做才能使其一键运行?
I have a form. In it I have a textarea which expands when onclick.
But there is a little problem:
When the user tries to submit the form (click the submit button), the textarea jumps back to its normal size. This is because it uses the onblur function. I want to eliminate this awkwardness, because the user has to click the submit button twice to submit the form.
What should I do to make it work with one click?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 onblur 处理程序中设置一个较短的超时来缩小文本区域:
You can set a short timeout in the onblur handler that shrinks the text area:
这将为
blur
事件添加一个侦听器,该事件将阻止触发任何其他事件,包括导致textarea
重新调整大小的任何事件。不过,对您来说,首先不添加blur
钩子会比以这种方式捕获它更容易。This will add a listener to the
blur
event which will prevent anything else from firing, including whatever it is that's causing thetextarea
to re-resize. It'd be easier for you to not add theblur
hook in the first place, rather than catching it this way, though.