2012-02-07 29 views
0

我有這樣 如何選擇表單元素和使用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($){} 

該行給出了空數組。爲什麼?我在選擇表單元素時做錯了什麼?

+0

可能重複[如何使用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

+0

不,不是重複的。我的id不能正常工作,正如你在你的文章中所建議的:(我認爲它是包含問題的腳本。 ..我在** Hemant Metalia **答案中添加了評論。你可以看到那裏。謝謝 – Basit 2012-02-08 05:38:59

回答

0

嘗試使用

$("[@id=validationFrom :mandotary]"); 

指博客http://rockycode.com/blog/ids-jsf-used-jquery/

+0

Atleast我理清了一個問題,但我不知道什麼是錯的 那個東西。我包括我的腳本,如** **。但是,當我將其更改爲** **即添加了目標屬性後,我的腳本開始工作。我不知道添加target = body是什麼效果,因爲腳本仍然包含在生成的HTML的頭部分。無論如何,但現在又發生了一件奇怪的事情。我添加了另一條評論.....看下面 – Basit 2012-02-08 05:28:05

+0

我有在我的表格id = formvalidation。當我給我的** **。然後嘗試下面的一個'var $ grid = $(document.getElementById('validationForm:mandotary'));','var $ grid1 = $('[id =「validationForm:mandotary」]');', 'var $ grid2 = $('#validationForm \\:mandotary');',那我什麼都沒有。即,我得到空陣列。但是當我給我的面板網格類,如'',然後嘗試'VAR $ grid4 = $('。mandotary');',那麼我得到** table.mandotary * *。我在做什麼錯了ID?在類的情況下我得到元素... – Basit 2012-02-08 05:33:03

+0

但是當我使用id我得到空。我在做什麼錯了ID的。這是包含問題的腳本。我必須在表單中包含腳本嗎?爲什麼發生這種情況?謝謝 – Basit 2012-02-08 05:34:28

相關問題