I'm not sure what I am doing wrong here. I want the enter key to work as well as clicking the button.
我不确定我在这里做错了什么。我想要输入键以及单击按钮。
<form action="" method="get" class="priceOptionForm" name="priceOptionForm"><input name="paypal_email" type="text" value="whatever" id="email"></label><a href="javascript:void(0);" class="bluebtn" id="profile_price" style="width:60px;margin-top:5px;">Save all</a></form>
7 个解决方案
#1
26
Try this:
document.getElementById('email').onkeydown = function(e){ if(e.keyCode == 13){ // submit }};
#2
7
Please use below code snippet...It should be added into script block
请使用下面的代码片段...它应该添加到脚本块中
<script> document.onkeydown=function(evt){ var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode; if(keyCode == 13) { //your function call here } }</script>
#3
6
All below codes should be added into script block or file.define submit function:
以下所有代码都应添加到脚本块或file.define提交功能中:
function submitForm(){ document.priceOptionForm.submit(); document.priceOptionForm.method='post';}
For the enter key to submit form:
对于提交表单的回车键:
document.onkeydown=function(){ if(window.event.keyCode=='13'){ submitForm(); }}
For the link to work:
要获得工作链接:
document.getElementById("profile_price").onclick=submitForm;
You can refer to http://jsfiddle.net/honglonglong/YMX2q/ for some trying.
您可以参考http://jsfiddle.net/honglonglong/YMX2q/进行一些尝试。
#4
5
Use an <input type="submit">
instead of a link. Then the enter key will work automatically.
使用而不是链接。然后输入键将自动运行。
#5
5
simply make a hidden button like this
HTML
只需创建一个像这个HTML的隐藏按钮
<input type="submit" id="submitbtn" />
CSS
#submitbtn{display:none;}
when the user will hit the enter button the form will be submitted
Don't forget to put the type="submit"
当用户点击回车按钮时,表单将被提交不要忘记输入type =“submit”
#6
1
// Process form if use enter key. put script in head. document.onkeyup = enter; function enter(e) {if (e.which == 13) submitForm();}// uses keyup not down as better practice imo // submitForm() is user function that posts the form
#7
-1
Oh that is because the HTML form element does not recognize the link as a button, to click..you need to replace it with a button...
哦,这是因为HTML表单元素无法将链接识别为按钮,单击..您需要用按钮替换它...
<input type="submit" value="this will display on your button" onClick="javascript:void(0)">
but if you want it to look like a link you should do this in the css
但如果你想让它看起来像一个链接你应该在CSS中做到这一点
<style type="text/css">input{background-color:white;border:0 none;}</style>
#1
26
Try this:
document.getElementById('email').onkeydown = function(e){ if(e.keyCode == 13){ // submit }};
#2
7
Please use below code snippet...It should be added into script block
请使用下面的代码片段...它应该添加到脚本块中
<script> document.onkeydown=function(evt){ var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode; if(keyCode == 13) { //your function call here } }</script>
#3
6
All below codes should be added into script block or file.define submit function:
以下所有代码都应添加到脚本块或file.define提交功能中:
function submitForm(){ document.priceOptionForm.submit(); document.priceOptionForm.method='post';}
For the enter key to submit form:
对于提交表单的回车键:
document.onkeydown=function(){ if(window.event.keyCode=='13'){ submitForm(); }}
For the link to work:
要获得工作链接:
document.getElementById("profile_price").onclick=submitForm;
You can refer to http://jsfiddle.net/honglonglong/YMX2q/ for some trying.
您可以参考http://jsfiddle.net/honglonglong/YMX2q/进行一些尝试。
#4
5
Use an <input type="submit">
instead of a link. Then the enter key will work automatically.
使用而不是链接。然后输入键将自动运行。
#5
5
simply make a hidden button like this
HTML
只需创建一个像这个HTML的隐藏按钮
<input type="submit" id="submitbtn" />
CSS
#submitbtn{display:none;}
when the user will hit the enter button the form will be submitted
Don't forget to put the type="submit"
当用户点击回车按钮时,表单将被提交不要忘记输入type =“submit”
#6
1
// Process form if use enter key. put script in head. document.onkeyup = enter; function enter(e) {if (e.which == 13) submitForm();}// uses keyup not down as better practice imo // submitForm() is user function that posts the form
#7
-1
Oh that is because the HTML form element does not recognize the link as a button, to click..you need to replace it with a button...
哦,这是因为HTML表单元素无法将链接识别为按钮,单击..您需要用按钮替换它...
<input type="submit" value="this will display on your button" onClick="javascript:void(0)">
but if you want it to look like a link you should do this in the css
但如果你想让它看起来像一个链接你应该在CSS中做到这一点
<style type="text/css">input{background-color:white;border:0 none;}</style>