上显示输入元素值 null" />

onkeyup="检查()";在 上显示输入元素值 null

发布于 2024-12-21 18:38:22 字数 720 浏览 0 评论 0 原文

在 primefaces 3.0.M3 中,使用 document.getElementById('confirmPassword') 将 textBox 值获取到 javaScript 时,会给出 null 值! 代码是: 在 primefaces 中:

<h:outputText value="Confirm Password*" />
<p:password
value="#{employeeRepositoryImpl.securityPrincipals.confirmPassword}"
required="true" label="Confirm Password" id="confirmPassword" for="confirmPassword" onkeyup="check()" >
update="confirmPassword" />
</p:password>

在 javaScript 中:

function check(){
    var title1 = document.getElementById('confirmPassword'); 
    var title2 = document.getElementById('password'); 
    alert(title1+title2);}

我设置了 prependId="false" 。但警报显示为空。还有其他方法可以做到这一点吗?

In primefaces 3.0.M3, While using document.getElementById('confirmPassword') for getting textBox value to javaScript, which gives a null value!
Code is:
in primefaces:

<h:outputText value="Confirm Password*" />
<p:password
value="#{employeeRepositoryImpl.securityPrincipals.confirmPassword}"
required="true" label="Confirm Password" id="confirmPassword" for="confirmPassword" onkeyup="check()" >
update="confirmPassword" />
</p:password>

in javaScript:

function check(){
    var title1 = document.getElementById('confirmPassword'); 
    var title2 = document.getElementById('password'); 
    alert(title1+title2);}

I have set prependId="false" . But alert shows null.Any other way to do the same?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大海や 2024-12-28 18:38:22

正如您所提到的,生成的 HTML 如下所示,

<input id="formId:confirmPassword_input" class="ui-inputfield ui-password ui-widget ui-state-default ui-corner-all" type="password" onkeyup="checkPass()" value="fd" name="formId:confirmPassword_input">

这意味着表单仍会从中附加 id,请重新检查这些组件所在的 h:form 并设置 prependId="false"

如果您尝试获取 ID 为 confirmPassword 的 HTML dom,它将返回 null,其中 HTML 中的实际 ID 为 formId:confirmPassword_input >

As you mentioned, the HTML that is generated is as below

<input id="formId:confirmPassword_input" class="ui-inputfield ui-password ui-widget ui-state-default ui-corner-all" type="password" onkeyup="checkPass()" value="fd" name="formId:confirmPassword_input">

which means still form appends id from it, please recheck your h:form under which these components lies and set the prependId="false"

and if you try to get the HTML dom with id confirmPassword it will return null where the actual ID in HTML is formId:confirmPassword_input

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文