简体   繁体   English

单击输入时将提交按钮设置为另一个

[英]Set submit button to another when clicking enter

I'm trying to set the submit button in an ASP.NET website to another submit button when clicking enter key on the keyboard. 单击键盘上的Enter键时,我试图将ASP.NET网站中的提交按钮设置为另一个提交按钮。 I've so far accomplished to do so, but problem is it still sends the second submit button too. 到目前为止,我已经做到了,但是问题是它仍然仍然发送第二个提交按钮。 I tried returning false in the onkeypress event in the input elements, but then it won't let me write anything to the text input boxes.. 我尝试在input元素的onkeypress事件中返回false,但是这样就不允许我在文本input框中写任何内容。

This is my javascript function: 这是我的javascript函数:

function button_click() {
    if (window.event.keyCode == 13) {
        document.getElementById("msSend").focus();
        document.getElementById("msSend").click();
    }
}

And a sample text input box: 和一个示例文本input框:

<input type="text" id="msname" name="msname" runat="server" onkeypress="button_click()" /></td>

Any suggestions? 有什么建议么?

I fixed it! 我修好了它! I had some buttons in my MasterPage that was for some reason defined as type="submit" . 我的MasterPage中有一些按钮,出于某些原因,它们被定义为type="submit" I changed: 我变了:

<button name="bmenu" onclick="DisableHL('bmenu'); location.href='<%= movies %>'; return false;" class="btn">סרטים</button>

to: 至:

<button name="bmenu" onclick="DisableHL('bmenu'); location.href='<%= movies %>'; return false;" class="btn" type="button">סרטים</button>

And there it fixed it! 并固定了它! ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击“ Enter”按钮时提交表单,并进行验证 - Submit form when Clicking “Enter” button, with validation addEventListener 'submit' 在单击按钮时正常工作,但在按 Enter 时不能正常工作 - addEventListener 'submit' working properly when clicking on button but not when pressing enter on(&#39;submit&#39;在单击<button>时</button>起作用, <button>但在输入字段上按Enter时不起作用</button> - on('submit' works when clicking the <button> but not when pressing enter on an input field 单击输入并按下提交按钮提交表单数据 - Submit form data both on clicking enter and hitting the submit button 用ENTER提交表单与单击提交按钮时的行为不同 - Different behavior when form is submitted with ENTER vs. clicking submit button 单击输入键/返回键应触发提交按钮 - Clicking the enter key/return key should trigger the submit button 为什么点击回车按钮提交输入在手机浏览器上不起作用? - Why submit input by clicking the enter button not work on mobile phone browsers? 提交按钮单击将其值更改为另一件事 - Submit button clicking changing the value of it to another thing 单击提交按钮时模拟“按入” - SImulate “Enter pressing” when submit button is clicked 按下ENTER时提交某个按钮 - Submit a certain button when ENTER is pressed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM