admin管理员组文章数量:1426051
i am using a form and i have to use button and type is submit when i pressed enter key the form submit, so i want to remove the functionality of enter key.
<input name="bb" id="bb" type="text" onKeyUp="Javascript: if(event.keycode==13) dont_submit(key); else show_error(this.value, event.keycode, this.id)";>
<script type="text/javascript">
function dont_submit(key)
{
if(key)
{
return false;
}
}
</script>
i also try this but not worked
<script type="text/javascript">
function dont_submit(key)
{
if(key == 13)
{
return false;
}
}
</script>
i am using a form and i have to use button and type is submit when i pressed enter key the form submit, so i want to remove the functionality of enter key.
<input name="bb" id="bb" type="text" onKeyUp="Javascript: if(event.keycode==13) dont_submit(key); else show_error(this.value, event.keycode, this.id)";>
<script type="text/javascript">
function dont_submit(key)
{
if(key)
{
return false;
}
}
</script>
i also try this but not worked
<script type="text/javascript">
function dont_submit(key)
{
if(key == 13)
{
return false;
}
}
</script>
Share
Improve this question
edited Sep 11, 2013 at 12:30
Sasidharan
3,7503 gold badges20 silver badges37 bronze badges
asked Sep 11, 2013 at 12:24
Ahad AhmedAhad Ahmed
491 silver badge7 bronze badges
1
-
1
Don't use
Javascript:
in event handlers! Where do people learn this? – epascarello Commented Sep 11, 2013 at 12:53
4 Answers
Reset to default 3Try this
$('#bb').on('keydown', function (e) {
if (e.keyCode == 13) {
return false;
}
});
DEMO
$(document).keypress(function (e) {
if(e.which == 13)
return false;
});
Simply don't put a submit button but rather plain button with JS to submit the form:
<input type="button" class="SubmitButton" value="Submit" onclick="this.form.submit();" />
If you're concerned about visitors without JavaScript, use such code:
<noscript>
<style type="text/css">
.SubmitButton { display: none; }
</style>
<input type="submit" value="Submit" />
</noscript>
$('#button').keypress(function () {
if(e.which == 13) {
return false;
}
});
本文标签: javascripthow to remove the enter key functionalityStack Overflow
版权声明:本文标题:javascript - how to remove the enter key functionality - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745391912a2656636.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论