我正在为我的应用程序使用两个单选按钮,显示已雇用和失业的状态。现在我必须使用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();
但是我无法获得价值,有人请求帮助
答案 0 :(得分:0)
我不是一个liferay开发人员,但是考虑到预期的呈现HTML,你的jQuery可能是$(input[name="employmentStatus"]:checked).val()
,它会以这种方式崩溃:
input
元素name
属性为&#34; employmentStatus&#34; :checked
val()
方法所以,如果您的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();