找到你要的答案

Q:How to pick up liferay radio button value using jQuery

Q:如何拿起Liferay单选按钮的值使用jQuery

I am using two radio buttons for my application which shows employed and unemployed status .Now i have to pick up the values using jQuery.So what i have tried is here

<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>

And this is the way i am picking up the radio button value.

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

But i am not able to pick up the value ,somebody please help

我用两个单选按钮为我的应用程序显示的就业和失业的状态。现在我不得不拿起值使用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();

但我不能拿起价值,有人请帮助

answer1: 回答1:

I'm not a liferay developer, but given the expected rendered HTML, your jQuery could be $(input[name="employmentStatus"]:checked).val(), which breaks down in this way:

  1. get me all input elements
  2. limit those inputs to the ones that have a name attribute of "employmentStatus"
  3. further limit to ones that are :checked
  4. Get the value of that input using the val() method

So, if your HTML looks like this:

<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() would set employementStatus to the string "Employed".

我不是一个系统的开发商,但鉴于预期呈现的HTML,你可以为jQuery(输入[名称=“工作情况”]:检查)。val(),打破了这种方式:

  1. get me all input elements
  2. limit those inputs to the ones that have a name attribute of "employmentStatus"
  3. further limit to ones that are :checked
  4. Get the value of that input using the val() method

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

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

employementstatus = $(输入[名称=“工作情况”]:检查)。val()将employementstatus到字符串“就业”。

jquery  liferay-6