[英]How to solve this onclick awkwardness?
http://jsfiddle.net/wmuYq/ http://jsfiddle.net/wmuYq/
I want to eliminate an awkwardness: the user has to click the submit button twice to submit the text. 我想消除尴尬:用户必须单击两次提交按钮才能提交文本。
What should I do to make it work with one click? 我应该怎么做才能一键工作?
You can set a timeout: http://jsfiddle.net/wmuYq/1/ 您可以设置超时: http : //jsfiddle.net/wmuYq/1/
document.getElementById("text1").onblur = function () {
var target = this;
setTimeout( function () {
target.style.height='36px';
}, 250);
}
You could use the onmousedown
event on the submit button to submit the form: 您可以使用提交按钮上的
onmousedown
事件来提交表单:
document.getElementById("submitButton").onmousedown = function() {
this.form.submit();
}
For the above example to work, you would need to give the button an ID. 为了使上面的示例起作用,您需要为按钮提供一个ID。 Also, you would need to change the name of the submit button from "submit" to something else, because otherwise it overwrites the
submit
property of the form
element. 另外,您还需要将提交按钮的名称从“ submit”更改为其他名称,因为否则它将覆盖
form
元素的submit
属性。
This works because the mousedown
event will be triggered on the button before the blur
event is triggered by the textarea
. 这之所以有效,是因为在
textarea
触发blur
事件之前,将在按钮上触发mousedown
事件。
Well for one thing you have no form, so I am not sure how it submits at all. 好吧,一件事您没有表格,所以我不确定它是如何提交的。
Wrap your code in a form and add an action and it should work fine :-) 将您的代码包装成表格并添加一个操作,它应该可以正常工作:-)
This might work. 这可能有效。 Untested
未经测试
Remove the onblur
event from the textarea
and place it as on onclick
on the input
取出
onblur
从事件textarea
,并把它作为上onclick
上input
onclick="document.getElementById('text1').style.height='36px'"
Revised fiddle: http://jsfiddle.net/jasongennaro/wmuYq/2/ 修正的小提琴: http : //jsfiddle.net/jasongennaro/wmuYq/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.