【问题标题】:a4j Command Button get focus on pressing Enter Keya4j 命令按钮专注于按 Enter 键
【发布时间】:2011-08-31 02:39:03
【问题描述】:

我的 jsf 页面上有一个 a4j 命令按钮,当我在页面的任意位置按 Enter 键时,此命令按钮获得焦点并执行其操作

我想防止按钮在按下 Enter 键时获得焦点 我尝试使用 onfocus="this.blur()" 但它不起作用

提前致谢

【问题讨论】:

    标签: javascript html jsf ajax4jsf


    【解决方案1】:

    <a4j:commandButton> 充当提交按钮。因此在按下回车时执行动作。

    当你看到生成的代码时,你会发现<input type="submit"/>

    要忽略您应该使用命令链接并看起来像按钮,请给出button 的样式,如下所示:

    .button {
        font: bold 11px Arial;
        text-decoration: none;
        background-color: #EEEEEE;
        color: #333333;
        padding: 2px 6px 2px 6px;
        border-top: 1px solid #CCCCCC;
        border-right: 1px solid #333333;
        border-bottom: 1px solid #333333;
        border-left: 1px solid #CCCCCC;
       }
    

    如果您仍然想使用<a4j:commandButton>,那么您可以使用阻止输入

     onkeypress="var keycode;
     if (window.event) { keycode = window.event.keyCode;}else {return true;}
     if (keycode == 13) {return false;}else {return true;}"
    

    但这会导致当你按下回车时,即使onfocus 也不会提交或调用操作,最好不要使用它

    【讨论】:

      猜你喜欢
      • 2021-07-30
      • 2011-12-26
      • 2017-04-18
      • 1970-01-01
      • 2021-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多