比如我有个值 =6 
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Value="2">今天</asp:ListItem>
                            <asp:ListItem Value="4">明天</asp:ListItem>
                            <asp:ListItem Value="6">昨天</asp:ListItem>
</asp:RadioButtonList>我想在RadioButtonList1上通过6显示出当前的状态,--- 状态就是 选定 "昨天"
但是要用JAVASCRIPT做
var level=document.getElementById("RadioButtonList1");
var aa = new Array(4);
aa=Insert_user.setName(v,dr1,dr1_bz,qsid).value;
username.innerText = aa[1];
pwd.innerText = aa[2];
zs_code.innerText = aa[3];
//level.Value = aa[0];
level[].checked;aa[0]=6;

解决方案 »

  1.   


    <script language="JavaScript">
    <!--
    var str = "6";
    window.onload = function(){
    var osel = document.getElementById("osel");
    for(var i = 0, len = osel.options.length;i < len; i++){
    if(osel.options[i].value == str){
    osel.options[i].selected = true;
    }
    }
    }
    //-->
    </script><select id="osel">
    <option value="2">今天</option>
    <option value="4">明天</option>
    <option value="6">昨天</option>
    </select>
      

  2.   

    这个是ASP控件啊.我试过了你的方法,然后做了些变通,没有效果啊,还是先感谢你
      

  3.   

    看看:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    <script language="javascript" type="text/javascript">
    // <!CDATA[function Button1_onclick(input) {var rbl=document.getElementsByName("RadioButtonList1");
    for(var i=0;i<rbl.length;i++)
    {
        if(rbl[i].value==input){
           // alert(rbl[i].value);
            rbl[i].checked=true;
        }
    }}// ]]>
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
          <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"> 
                                <asp:ListItem Value="2">今天 </asp:ListItem> 
                                <asp:ListItem Value="4">明天 </asp:ListItem> 
                                <asp:ListItem Value="6">昨天 </asp:ListItem> 
    </asp:RadioButtonList> 
            <input id="Text1" type="text" />
            <input id="Button1" type="button" value="button" onclick="return Button1_onclick(document.getElementById('Text1').value)" /></div>
        </form>
    </body>
    </html>