2012-02-07 55 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