[英]How could I solve this onclick-onblur problem?
I have a form. 我有一个表格。 In it I have a textarea which expands when onclick.
在其中,我有一个textarea,在单击时会扩展。 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.
这是因为它使用了onblur函数。 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? 我应该怎么做才能一键工作?
You can set a short timeout in the onblur handler that shrinks the text area: 您可以在onblur处理程序中设置较短的超时时间,以缩小文本区域:
document.getElementById("textareaID").onblur = function () {
var target = this;
setTimeout( function () {
//Code to shrink the textarea, use "target" instead of "this" for scoping reasons.
}, 250);
}
textArea.addEventListener('blur', function(e) {
e.preventDefault();
return false;
}, true);
This will add a listener to the blur
event which will prevent anything else from firing, including whatever it is that's causing the textarea
to re-resize. 这会将侦听器添加到
blur
事件中,以防止触发其他任何事件,包括导致textarea
调整大小的所有内容。 It'd be easier for you to not add the blur
hook in the first place, rather than catching it this way, though. 不过,您最好不要首先添加
blur
钩子,而不是像这样捕获它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.