JSF CommandButton onclick不会调用Javascript函数

问题描述 投票:5回答:3

我正在使用JSF中的命令按钮。我不知道为什么我不能调用我的javascript函数。当我单击按钮时,不会显示警报。

<h:commandButton id="login" value="Login" action="login"
   onclick="return checkPasswords();" type="Submit" /> 

我的Javascript函数:

function checkPasswords() {
    alert("test");
    return false;
}
jsf button command onclick
3个回答
5
投票
  1. 检查您生成的代码(打开页面->查看源代码)
  2. 检查您的JavaScript控制台(Firefox)是否有错误
  3. 确保您的函数可从普通<input type="button">调用
  4. 小写您的按钮类型。

否则,它应该工作-我的当前代码库中有完全相同的代码,可以正常工作。


3
投票

这正在工作

<script type="text/javascript">
function checkPasswords() {
   alert("test");
   return false;
}
</script>

<h:commandButton  id="login" value="Login" action="login"
             onclick="checkPasswords();" type="submit"/>

2
投票

在type =“ submit”中以小写形式给出,type属性设置要为此组件创建的按钮的类型。此属性的有效值为“提交”和“重置”。此属性的默认值为“提交”。

© www.soinside.com 2019 - 2024. All rights reserved.