禁用输入键 [英] Disable Enter Key

查看:41
本文介绍了禁用输入键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的JSF页面中禁用 Enter 键.我是JavaScript新手.如果可以使用JS,如何绑定JS和Primefaces组件.

I want to disable Enter key in my JSF page. I am new to JavaScript. If it is possible with JS, how can I bind JS and Primefaces components.

推荐答案

您的所有组件都有一个ID,如果没有,请创建一个ID,JS有必要知道与他一起工作的人.

All your components have a ID, if it doesn't, create it, it is necessary for JS to know with who he is working with.

这是代码的安全性,它是jQuery:

Here is a peace of code, it is jQuery:

$('#your_element_id').keypress(function(e)
{
   if ( event.which == 13 ) {
     event.preventDefault();
   }
});

它将阻止 enter 执行任何操作.

It will block the enter to execute anything.

这篇关于禁用输入键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆