[英]Isuue with getting the value of inputHidden from a4j:form by javascript
I have the following issue.我有以下问题。 I need to get the hidden value that is in a4j:form from javascript.
我需要从 javascript 中获取 a4j:form 中的隐藏值。
<a4j:form id="orderModalFormId">
<h:form style="display:none;" prependId="false">
<h:inputHidden id="maxVal" value="#{bean.maxVal}"/>
</h:form>
//...rest code where javascript is used
</a4j:form>
in javascript在 javascript
...
var maxValue = jQuery('#orderModalFormId : maxVal').val();
...
The problem is that during javascript debugging maxValue remains still undefined.问题是在 javascript 调试过程中 maxValue 仍未定义。 I'm pritty new in javascript and jQuery.
我是 javascript 和 jQuery 的新手。 Where is a trick?
诡计在哪里? Thanks!
谢谢!
Creating the HTML psychically is tricky, but you almost certainly want just a simple id
selector:从心理上创建 HTML 很棘手,但您几乎可以肯定只需要一个简单的
id
选择器:
var maxValue = jQuery('#maxVal').val();
From the edit, it seems like you need this:从编辑中,您似乎需要这个:
var maxValue = jQuery('#orderModalFormId\\:maxVal');
You need to escape the :
so that jQuery doesn't parse it as a pseudo-selector.您需要转义
:
以便 jQuery 不会将其解析为伪选择器。 You need to use an escaped backslash ( \\:
) so that Javascript doesn't interpret \:
as an escaped colon.您需要使用转义的反斜杠(
\\:
),以便 Javascript 不会将\:
解释为转义的冒号。
See jsFiddle for an example of an escaped colon in an id
selector .有关
id
选择器中转义冒号的示例,请参见 jsFiddle 。
The :
is an illegal character in CSS selectors and those spaces doesn't make it better. :
是 CSS 选择器中的非法字符,这些空格并不能使它变得更好。
Either use good ol' JS:要么使用好的 ol' JS:
var value = document.getElementById("orderModalFormId:maxVal").value;
Or escape it by double backslash:或者通过双反斜杠转义它:
var value = jQuery("#orderModalFormId\\:maxVal").val();
Or use the jQuery attribute selector:或者使用 jQuery 属性选择器:
var value = jQuery("id=['orderModalFormId:maxVal']").val();
Or when the JS is embedded in a JSF page (and you're using RichFaces already):或者当 JS 嵌入到 JSF 页面中时(并且您已经在使用 RichFaces):
var value = #{rich:component('maxVal')}.val();
Actually, both of you were right about the syntax but the problem was of another nature.实际上,你们俩在语法上都是对的,但问题是另一种性质的。 It appeared that my ajax form didn't work with my javascript properly, so what i did was just pathing parameter of maxVal into this a4j:form by means of ui:include (my a4j:form is in separate xhtml file).
看来我的 ajax 表单无法正常与我的 javascript 一起使用,所以我所做的只是通过 ui:include 将 maxVal 的参数输入到这个 a4j:form 中(我的 a4j:form 在单独的 xhtml 文件中)。 Like this:
像这样:
mainPage.xhtml主页面.xhtml
<h:form style="display:none;" prependId="false">
<h:inputHidden id="maxVald" value="#{mainBean.maxVal}"/>
</h:form>
<ui:include src="/xhtml/include/orderModalForm.xhtml">
<ui:param name="maxVal" value="#{mainBean.maxVal}"/>
</ui:include>
and in javascript i did like this在 javascript 我喜欢这个
var maxFreezePeriod = jQuery('#maxFreezePeriod').val();
Thanks for your answers:)感谢您的回答:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.