设置按下回车键时触发的图像按钮
显然我知道如何在 ASP.NET Web 表单中使用 DefaultButtons 来执行此操作。然而,我们的客户端开发人员编写代码的方式是通过 javascript 完成提交按钮:
因此 javascript 正在渲染 HTML。
<img id="submitBMI" onclick="quizCalc(); return false;" class="btnHover" src="Submit.gif">
有没有办法让它成为默认按钮?
谢谢你们。
Obviously I know how to do this with DefaultButtons within an ASP.NET web form. However, the way our client side developer wrote the code, he has a submit button done via javascript:
So the javascript is rendering the HTML.
<img id="submitBMI" onclick="quizCalc(); return false;" class="btnHover" src="Submit.gif">
Is there anyway to make this a DefaultButton?
Thanks guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
打算在该表单的文本框中按下 Enter 键时调用 quizCalc() 方法,那么您只需设置表单的 onsubmit 处理程序来调用该方法:
例如,如果您 更多地控制哪些输入元素调用该方法,然后您可以考虑将 onkeypress 与单个处理程序 onKeyPress(event) 一起使用,请查看 类似问题
更新
您可以按照乔纳森所说的操作,但只需删除 return false 即可取消按键从向文本框添加字符。
If you mean to have the quizCalc() method be called when, for example, the enter key is pressed in a textbox of that form, then you could just set the onsubmit handler of the form to call that method:
If you want a little more control on which input elements call the method then you could look at using onkeypress with a single handler onKeyPress(event), check out a similar question
Update
You could do what Jonathan says, but just remove the return false as that cancels the keypress from adding characters to the textbox.
假设您没有使用 js 库,如果在页面上的任意位置按下 Enter 键,这将起作用:
Assuming you aren't using a js library, this will work if enter is pressed anywhere on the page: