我在选择时有一个单选按钮列表 我遇到了以下代码的一个问题,因为我只在 js 函数中为其他人获取第一个单选按钮的值(我的意思是除了第一个单选按钮之外),它给出了 null。 PFB代码
<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>
我的java脚本函数
$("#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);
并在您的 JSP 文件中使用 <input type="hidden" id="radioValueArrya" name="radioValueArrya"/>
并在您的 Controller 中添加参数 @RequestParam List<String> radioValueArrya
在你的方法中
关于javascript - 如何将单选按钮名称列表传递给 spring Controller 并将它们显示到成功页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28670644/