简体   繁体   English

如何解决这种onclick尴尬?

[英]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事件。

Here's a working example . 这是一个有效的例子

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 ,并把它作为上onclickinput

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.

相关问题 如何解决 typescript Reactjs 中的 onClick 问题 - how to solve the onClick problem in typescript Reactjs OnClick解方程 - OnClick Solve equation 如何解决 ReferenceError: myfunction123 is not defined at HTMLButtonElement.onclick? - How to solve ReferenceError: myfunction123 is not defined at HTMLButtonElement.onclick? 我该如何解决onclick-onblur问题? - How could I solve this onclick-onblur problem? onclick不适用于动态创建的按钮..在这种情况下如何解决呢? - onclick not working for dynamically created button .. how to solve this in this particular case? 我该如何解决这个问题? 未捕获的类型错误:无法读取 HTMLButtonElement.botonContinuar.onclick 处未定义的属性“textContent” - How do i solve this issue? Uncaught TypeError: Cannot read property 'textContent' of undefined at HTMLButtonElement.botonContinuar.onclick 如何解决Uncaught SyntaxError:在PHP echo内部使用onclick将字符串传递给javascript函数时出现意外标识符 - how to solve Uncaught SyntaxError: Unexpected Identifier while passing a string to javascript function using onclick inside PHP echo 如何解决这个未捕获的引用错误:like_post 未在 HTMLAnchorElement.onclick 中定义? - How do I solve this uncaught reference error: like_post is not defined at HTMLAnchorElement.onclick? php javascript echo onjavascript变量使用onclick动态地达到php循环条件,或者如何使用Ajax解决它? - php javascript echo javascript variable to php loop condition dynamically using onclick or how can I use ajax to solve it? 在 object 中使用名为 __proto__ 的键创建属性的尴尬 - Awkwardness creating a property in an object with a key called __proto__
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM