日期:2014-05-20  浏览次数:20763 次

求一radio 的问题
选项一<input type="radio" name="wlcode" value="1" checked />

选项二:<input type="radio" name="wlcode" value="2" />

然后将选中的值送入后台处理,后台返回一个选中的radio的值

现在就是问下 如何手动设置radio为选中状态

现在的情况是不管radio的值是什么,都是选项一是选中的状态

不知道有没有说清楚


------解决方案--------------------
给你贴一个radio标签的实例,第二项为默认选中状态
HTML code

<html>
<head><title>选择</title></head>
<body>
请选择你最喜欢的水果:<br>
<form action = "http://www.admin5.com/html/asdocs/html_tutorials/choose.asp" method = "post">
<input type="radio" name="fruit" value = "Apple">苹果<br>
<input type="radio" name="fruit" value = "Orange" checked>桔子<br>
<input type="radio" name="fruit" value = "Mango">芒果<br>

<input type="submit" value="提交">
</form>
</body>
</html>

------解决方案--------------------
选项一<input type="radio" name="wlcode" value="1" />

选项二:<input type="radio" name="wlcode" value="2" checked />

调换一下checked到第二项来就行了。
 

------解决方案--------------------
判断一下
------解决方案--------------------
根据条件来判断哪项选中就把checked="checked"这个加上啊。例如JSP 可以用
<%if (条件){%> checked="checked" <%}%>

------解决方案--------------------
就看你是怎么写了,你后台传送过来的页面里可以加一个标记变量,在前台判断下,在第一个还是第二个radio标签中添加checked
------解决方案--------------------
<input type="radio" <c:if test="${filter.aliveFlag eq '' }">selected</c:if>>--全部--</option>
<input type="radio" <c:if test="${filter.aliveFlag eq '1' }">selected</c:if>>--已授权&nbsp;--</option>
<input type="radio" <c:if test="${filter.aliveFlageq '0' }">selected</c:if>>--取消&nbsp;--</option>

做一个if else判断就行了。。。。
------解决方案--------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function initSelect(selObj,val){ 
for(i=0;i<selObj.length;i++){
if(val==selObj[i].value){
selObj.selectedIndex=i;
}
}
}

</script>
</head>
<body >
<form name="opForm">
<select name="test" id="test">
<option value="" >-全部-</option>
<option value="1">北京</option>
<option value="2">上海</option>
<option value="3">天津</option>
</select> 
<script>initSelect(document.opForm.test,2); </script>
</form>
</body>
</html>
select下面调用的initSelect函数第二个参数写你后台返回的参数,我此处为了看出结果写的2