如何将单选按钮名称传递给弹簧控制器,并将它们显示给成功页面 [英] how to pass the list of radio buttons name to spring controller and show them to the success page

查看:124
本文介绍了如何将单选按钮名称传递给弹簧控制器,并将它们显示给成功页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单选按钮列表,同时选择
我正面临一个问题,下面的代码,因为我只有第一个单选按钮在我的js函数中为其他人(我的意思是除第一个广播之外)的值给零。 PFB代码

 < tr> < TD> < input type =radioid =selectedTempListname =templatevalue =$ {templateList.finalTemplateName}onclick =getSelectedTempName()>< / td> < td>< c:out value =$ {templateList.finalTemplateName}>< / c:out>< / td>< / tr> 

我的Java脚本函数

  $(#selectedTempList)。each(function(){
if($(this).is(':checked'))
selectedTemplateName = $(this) .val();
});
alert(无线电选择值+ selectedTemplateName);

$ b


解决方案

var radioValueArrya = [];
$(#r1)。each(function(){
if($(this).is(':checked'))
radio1 = $(this).val );
radioValueArrya.push(radio1);
alert(radio select values+ radio1);
});


$ b $(#r2)。each(function(){
if($(this).is(':checked'))$
radio2 = $(this).val();
radioValueArrya.push(radio2);
alert(radio select values+ radio2);
});
//控制器调用
$(#divid)。load($ {contextPath} / actionName?kRadio =+ escape(radio1)++
& sRadio =
++ escape(radio2)+& radioValueArrya =+ radioValueArrya);

并且在您的JSP文件中使用< input type =hiddenid =radioValueArryaname =radioValueArrya/>



并且在你的Controller中添加参数 @RequestParam List<串GT;您的方法中的radioValueArrya


I have a list of radio buttons while selecting I am facing one issue with below code as i am getting only value of first radio button in my js function for others (i mean other than first radio) it is giving null. PFB code

 <tr> <td> <input type="radio" id="selectedTempList" name="template" value="${templateList.finalTemplateName}" onclick="getSelectedTempName()"></td> <td><c:out value="${templateList.finalTemplateName}"></c:out></td></tr> 

My java script function

 $("#selectedTempList").each(function() {
     if($(this).is(':checked'))
         selectedTemplateName=$(this).val();
     });
     alert("radio select values"+selectedTemplateName);

 }

解决方案

var radioValueArrya = [];
$("#r1").each(function() {
        if($(this).is(':checked'))
        radio1=$(this).val();
        radioValueArrya.push(radio1); 
        alert("radio select values"+radio1);
    });



 $("#r2").each(function() {
        if($(this).is(':checked'))
            radio2=$(this).val();
            radioValueArrya.push(radio2);
        alert("radio select values"+radio2);
    });   
// controller call 
 $("#divid").load("${contextPath}/actionName?kRadio="+escape(radio1)  +"" +
                    "&sRadio="
                    +"" +escape(radio2)+"&radioValueArrya="+radioValueArrya); 

And in your JSP file use <input type="hidden" id="radioValueArrya" name="radioValueArrya"/>

And in your Controller add parameter @RequestParam List<String> radioValueArrya in your method

这篇关于如何将单选按钮名称传递给弹簧控制器,并将它们显示给成功页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆