如何从JSF 2.0中的javascript获取元素
问题描述:
我有JSF代码,例如:
I have JSF code like:
<h:inputText id="from" value="#{fromToMBean.fromName}"/>
我想通过ID(from
)从JavaScript中获取此元素,但是我不能,因为在生成的HTML中它是j_idt8:from
I would like to get this element from JavaScript by ID (from
), but I can't, because in generated HTML it is j_idt8:from
如何在例如jQuery的?有什么方法可以强制JSF2不更改ID?
How can I get this element in e.g. jQuery? Is there any way to force JSF2 not to change ids?
答
您可以使用仅分配给该元素的自定义类,并使用css选择器,或者为表单分配一个id并获取具有id的元素formid:from
.
You can either use a custom class which you only assign to this element and use css selectors or assign an id to the form and get the element with the id formid:from
.