我有這樣 如何選擇表單元素和使用jQuery
<h:form id="validationFrom" >
<div id="mandotary" >
<h:panelGrid columns="4"
border="1"
width="50%"
style=""
columnClasses="asteriskColumns, nameColumns" >
<h:outputLabel value="*" style="color: red;" />
<h:outputLabel value="Heading: " />
<h:inputText id="heading" value="#{validation.heading}" />
<h:message id="headingMessage" for="heading" style="color: red" />
<h:outputLabel value="*" />
<h:outputLabel value="Select Category Type :" />
<h:selectOneRadio id="selectCategoryRadioButton"
rendered=""
value="#{validation.selectedRadioButton}"
layout="layoutDirection">
<f:selectItems value="#{validation.radioButtonItems}"/>
</h:selectOneRadio>
<h:panelGroup />
<h:outputLabel value="*"
rendered=""/>
<h:outputLabel value="Broad Category :"
rendered=""/>
<h:selectOneMenu id="broadCategory"
rendered=""
value="#{validation.selectedBroadCategory}" >
<f:selectItems value="#{validation.broadCategoryItemsList}"/>
</h:selectOneMenu>
<h:message id="broadCategoryMessage" for="broadCategory" style="color: red" />
<h:outputLabel value="*" />
<h:outputLabel value="Sub Category :" />
<h:selectOneMenu id="subCategory"
value="#{validation.selectedSubCategory}"
style="width: 250px;">
<f:selectItem itemLabel="---Select---" noSelectionOption="true" />
<f:selectItems value="#{validation.subCategoryItemsMap}"/>
</h:selectOneMenu>
<h:message id="subCategoryMessage" for="subCategory" style="color: red" />
<h:outputLabel value="*" style="color: red;" />
<h:outputLabel value="Description: " />
<h:inputText id="description" value="#{validation.description}" />
<h:message id="descriptionMessage" for="description" style="color: red" />
</h:panelGrid>
</div>
<h:commandButton id="saveButton"
value="Save"
action ="null"/>
<h:commandButton id="cancelButton"
value="Cancel"
action="null" />
</h:form>
</h:body>
現在我要選擇帶班mandoroty形式和DIV在JSF2.0一種形式,其JSF2.0孩子,這樣我就可以檢查div中的所有元素。我正在嘗試此操作,但它不起作用
(function($){
var mandotoryFieldsArray = $("#validationFrom div.mandotary")
var test;
})(jQuery); //end of (function($){}
該行給出了空數組。爲什麼?我在選擇表單元素時做錯了什麼?
可能重複[如何使用jQuery選擇PrimeFaces UI或JSF組件?](http://stackoverflow.com/questions/7927716/how -to-select-primefaces-ui-or-jsf-components-using-jquery) – BalusC 2012-02-07 14:01:45
不,不是重複的。我的id不能正常工作,正如你在你的文章中所建議的:(我認爲它是包含問題的腳本。 ..我在** Hemant Metalia **答案中添加了評論。你可以看到那裏。謝謝 – Basit 2012-02-08 05:38:59