1

我有一个带有数据和单选按钮的表格,可以检查:接受、待处理、拒绝。在保存时,我想检查是否有任何单选按钮仍处于待处理状态。我怎样才能做到这一点?

单选按钮如下所示:

<td class="fit">
 <table>
  <tr>
   <td class="pad0"><div class=""><fmt:message key='status.registration.registered'/>:</div></td>
   <c:if test="${participation.registrationStatus == 2}"><td class="pad0 padL10"><spring:radiobutton path="assignmentFormArray[${i}].registrationStatus" value="2" checked="checked"/></td></c:if>
   <c:if test="${participation.registrationStatus != 2}"><td class="pad0 padL10"><spring:radiobutton path="assignmentFormArray[${i}].registrationStatus" value="2"/></td></c:if>
  </tr><tr>
   <td class="pad0"><div class=""><fmt:message key='status.registration.pending'/>:</div></td>
   <c:if test="${participation.registrationStatus == 1}"><td class="pad0 padL10"><spring:radiobutton path="assignmentFormArray[${i}].registrationStatus" value="1" checked="checked"/></td></c:if>
   <c:if test="${participation.registrationStatus != 1}"><td class="pad0 padL10"><spring:radiobutton path="assignmentFormArray[${i}].registrationStatus" value="1"/></td></c:if>
  </tr><tr>
   <td class="pad0"><div class=""><fmt:message key='status.registration.declined'/>:</div></td>
   <c:if test="${participation.registrationStatus == 6}"><td class="pad0 padL10"><spring:radiobutton path="assignmentFormArray[${i}].registrationStatus" value="6" checked="checked"/></td></c:if>
   <c:if test="${participation.registrationStatus != 6}"><td class="pad0 padL10"<spring:radiobutton path="assignmentFormArray[${i}].registrationStatus" value="6"/></td> </c:if>
  </tr>
 </table>
</td>

我尝试了以下 Javascript 函数:

function save(){
 alert($("input:radio[value='1']:checked"));
}

不幸的是,这不起作用。即使没有选择值为 1 的单选按钮,它也会始终使用对象发出警报。

4

3 回答 3

0
   $('input:radio[name=name of radio button]:checked').val();

这将为您提供所选单选按钮的值..您可以检查该按钮是挂起还是接受或拒绝...

于 2012-10-23T09:48:16.493 回答
0

我找到了解决方案。但感谢任何想提供帮助的人:

function save() {
 var isPending = false;
 $("input[type='radio']:checked").each(function(){
    if ($(this).val() == 1){
        isPending = true;
    };
 });
 if (isPending){
    alert("isPending");
 }
}
于 2012-10-23T10:12:02.543 回答
0

i think u can create a simple boolean array which stores the values of the radio buttons on change of radio buttons u need to call a set method every time this is just like a bean to set and get the values of the form element , on save u can simply check the boolean array

于 2012-10-23T10:37:21.170 回答