jsp获取radio的值

我现在在jsp中这样一个radio:
<input type="radio" name="keyMan" value=""/>是
<input type="radio" name="keyMan" value=""/>否
我在后台返回一个“是”,请问我怎么在页面上显示选择在是上?

首先你的代码是有问题的,你选“是”还是“否”的标准时你的value值,然而你的value值现在都是空字符串。你这样写

在后台不要返回是,返回数字1或者0赋值给变量i。
<%int i = request.getParameter("value");%>
<input type="radio" name="keyMan" value="1" <%if(i==1){out.print("select");} %>/>是
<input type="radio" name="keyMan" value="0" <%if(i==1){out.print("select");} %>/>否
这样你就可以动态的控制radio的默认选择了。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-05-26
首先你的代码是有问题的,你选“是”还是“否”的标准时你的value值,然而你的value值现在都是空字符串。你这样写
在后台不要返回是,返回数字1或者0赋值给变量i。
<%int
i
=
request.getParameter("value");%>
<input
type="radio"
name="keyMan"
value="1"
<%if(i==1){out.print("select");}
%>/>是
<input
type="radio"
name="keyMan"
value="0"
<%if(i==1){out.print("select");}
%>/>否
这样你就可以动态的控制radio的默认选择了。
第2个回答  2009-05-19
首先要获得radio的数组。然后遍历该数组找到checked()的那个radio。最后.value获得值,就这么简单。
第3个回答  推荐于2018-03-04
用脚本吧:

var keyManValue = 你从后台得到的值

var radios = document.getElementsByName("keyMan");
for(var i=0;i<radios.length;i++){
if(keyManValue='是’){
radios[0].checked = true;
}else{
radios[1].checked = true;
}
}本回答被网友采纳
第4个回答  推荐于2016-03-05
可以通过元素的name属性,获取到相同的值,只会根据radio的checked属性来获取到被选中的元素:
<form action="c.jsp"onsubmit="check();">
<input type=radio name="a" value=0>0
<input type=radio name="a" value=1>1
<input type=radio name="b" value=0>0
</form>

<script type="text/javascript">
function check(){
var i,flag=0;
var obj1=document.getElementsByName("a");
for(i=0;i<obj1.length;i++){
if(obj1[i].checked){
flag=1;
}
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网