如何使用jQuery获取liferay单选按钮值

时间:2015-06-23 14:32:13

标签: jquery liferay-6

我正在为我的应用程序使用两个单选按钮,显示已雇用和失业的状态。现在我必须使用jQuery来获取值。所以我试过的就是这里

<tr>
                <th>Current Employment status<span style='color: #FF0000; display: inline;'>*</span></th>
                <td>
                    <c:choose>
                        <c:when test='<%= employmentStatus.equals("Employed") %>'>
                            <aui:input checked="<%=true%>" inlineField="true" label="Employed" value="Employed" type="radio" name="employmentStatus" id="employed"></aui:input>
                            <aui:input inlineField="true" label="Not Employed" value="Not Employed" type="radio" name="employmentStatus" id="notEmployed"></aui:input>
                        </c:when>
                        <c:when test='<%= employmentStatus.equals("Not Employed") %>'>
                            <aui:input inlineField="true" label="Employed" value="Employed" type="radio" name="employmentStatus" id="employed"></aui:input>
                            <aui:input checked="<%=true%>" inlineField="true" label="Not Employed" value="Not Employed" type="radio" name="employmentStatus" id="notEmployed"></aui:input>
                        </c:when>
                        <c:when test='<%= employmentStatus.equals("") %>'>
                            <aui:input checked="<%=true%>" inlineField="true" label="Employed" value="Employed" type="radio" name="employmentStatus" id="employed"></aui:input>
                            <aui:input inlineField="true" label="Not Employed" value="Not Employed" type="radio" name="employmentStatus" id="notEmployed"></aui:input>
                        </c:when>
                    </c:choose> 
                </td>
            </tr>

这就是我拿起单选按钮值的方式。

employementStatus=$('#<portlet:namespace/>employed').val();

但是我无法获得价值,有人请求帮助

2 个答案:

答案 0 :(得分:0)

我不是一个liferay开发人员,但是考虑到预期的呈现HTML,你的jQuery可能是$(input[name="employmentStatus"]:checked).val(),它会以这种方式崩溃:

  1. 给我所有input元素
  2. 将这些输入限制为name属性为&#34; employmentStatus&#34;
  3. 的输入
  4. 进一步限制为:checked
  5. 使用val()方法
  6. 获取该输入的值

    所以,如果您的HTML看起来像这样:

    <input checked="true" value="Employed" type="radio" name="employmentStatus" id="employed" />
    <input value="Not Employed" type="radio" name="employmentStatus" id="notEmployed" />
    

    employementStatus=$(input[name="employmentStatus"]:checked).val()会将employementStatus设置为字符串&#34; Employed&#34;。

答案 1 :(得分:0)

此代码可能会有所帮助:

$('input[name="<portlet:namespace/>employmentStatus"]:checked').val();