0

我有以下表单,当我单击下一步按钮时,我试图获取隐藏表单字段“kpiValueType”的值。

<script type="text/javascript">
    function getGivenFieldValue()
    {
        var searchFieldVal = jQuery('input:hidden[name="activities[0].kpiList[0].kpiValueType"]').val();
        alert(searchFieldVal);
    }
</script>

<h:form id="fundRequestForm" action="" method="post">
    <ui:repeat value="#{fundRequestBean.requestActivityList}" var="activity" varStatus="stat">
        <table width="100%" class="tablesorter">
            <thead class="fixedHeader">
                <tr>
                    <th width="418px">
                            <input type="checkbox" checked="checked" name="activities[#{stat.index}].check" />
                        #{activity.activityName}
                    </th>
                    <th>&nbsp;</th>
                </tr>
            </thead>
            <tbody>
                <ui:repeat value="#{activity.kpiList}" var="kpi" varStatus="status">
                    <tr>
                        <td>#{kpi.kpiName}<ui:fragment rendered="#{kpi.required=='true'}">
                                <label style="color: red">*</label>
                            </ui:fragment>
                        </td>
                        <td><div style="text-align: left; padding-top: 5px; padding-bottom: 5px; float: left;">
                                <input type="text" name="activities[#{stat.index}].kpiList[#{status.index}].kpiValueString"
                                        value="#{kpi.kpiValueString}" size="60" maxlength="50" />
                        </td>
                    </tr>
                    <input type="hidden" name="activities[#{stat.index}].kpiList[#{status.index}].kpiValueType"
                        value="#{kpi.kpiValueType}" />
                </ui:repeat>
            </tbody>
        </table>
    </ui:repeat>

    <table width="100%" border="0" bordercolor="#CCCCCC" rules="none" cellspacing="0" cellpadding="0">
        <tr>
            <td colspan="3" align="center">&#160;&#160;&#160;&#160;</td>
        </tr>
        <tr>
            <td>&#160;&#160;&#160;&#160;</td>
            <td>&#160;&#160;&#160;&#160;</td>
            <td align="right"><div id="nextButtonDiv" style="float: right;">
                    <h:commandButton
                        onclick="getGivenFieldValue()"
                        actionListener="#{fundRequestBean.saveFundRequest}" action="#{fundRequestBean.getPreviewFundRequestData}"
                        value="#{msg.nextLbl}">
                    </h:commandButton>
                </div>&#160;&#160;&#160;&#160;&#160;&#160;&#160;</td>
        </tr>
        <tr>
            <td colspan="3" align="center">&#160;&#160;&#160;&#160;</td>
        </tr>
    </table>
</h:form>

从页面源中,我看到隐藏字段 kpiValueType 的名称为

<input type="hidden" name="activities[0].kpiList[0].kpiValueType" value="N" />

警报给我未定义。你能告诉我这里有什么问题吗?我正在使用 jQuery 1.7 和 Firefox 13.0.1

4

1 回答 1

1

您需要转义.选择器中的字符:

var searchFieldVal = jQuery('input:hidden[name="activities[0]\\.kpiList[0]\\.kpiValueType"]').val();
alert(searchFieldVal);

这是一个工作示例

于 2012-07-17T14:39:54.190 回答