在前台有一组radio(r1,r2,r3)--html控件
在CS文件中怎样设置r1或r2,或r3为选中我想要的效果是,从另外一个页面传过来一个值(‘男/女/不限’)
r1(男),r2(女),r3(不限)
如果传过来的值事‘男’则r1选中,‘女’r2选中(声明radio为html控件,非服务器控件)大家帮下忙
在CS文件中怎样设置r1或r2,或r3为选中我想要的效果是,从另外一个页面传过来一个值(‘男/女/不限’)
r1(男),r2(女),r3(不限)
如果传过来的值事‘男’则r1选中,‘女’r2选中(声明radio为html控件,非服务器控件)大家帮下忙
还请高人出现
radio.checked = true;
同意
给radio一个idrid.checked=true就是选中
后台直接
if(传的是"男")
{
radio男(ID).Checked=true;
}
else if("女")
{
radio女(ID).Checked=true;
}
else
{
radio不限(ID).Checked=true;
}
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal" Width="156px">
<asp:ListItem Selected="True">型男</asp:ListItem>
<asp:ListItem>索女</asp:ListItem>
</asp:RadioButtonList>
后台:
string photo=null;
if (this.RadioButtonList1.SelectedValue == "型男")
{
photo = "images/GG.gif";
}
else
{
photo = "images/MM.gif";
}
<input type="radio" value="男" <%= (Request.QueryString["sex"]=="男")? "checked":""%>/>
<input type="radio" value="女" <%= (Request.QueryString["sex"]=="女")? "checked":""%>/>
<input type="radio" value="不限" <%= (Request.QueryString["sex"]=="不限")? "checked":""%>/>
我需要的是这种
Response.RegisterClientScript(" <script>选中radio的js </script>");
function CheckedRad(radId,strSex)
{
if(parseInt(radId) > 0)
{
var rad = document.getElementsByName("radSex");
if(rad != null)
{
for(var i = 0; i < rad.length ; i++)
{
if(rad[i].value == strSex)
{
rad[i].checked = true;
}
}
}
}
}
</script>
然后 Response.RegisterClientScript(" <script> CheckedRad(1,男)</script>");
Response.RegisterClientScript(" <script> CheckedRad(1,男)</script>");
Response.RegisterClientScript(" <script> CheckedRad(1,男)</script>");
这两个参数你自己看着处理