js为select动态添加option,使用webservice提供数据

 <head runat="server">
    <title>动态添加option</title>
    <script>
        function myclick()
        {
            WebService.GetDayEnum(onSuccess);
        }
        function onSuccess(result)
        {
            var myselect= document.getElementById("myselect");
            for(var i=0;i<8;i++)
            {
                myselect.options[i] = new Option(result[i],i); 
            }
        }
    </script>
</head>
<body onload="myclick();">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Services>
            <asp:ServiceReference Path="~/WebService.asmx" />
        </Services>
    </asp:ScriptManager>
    <div>
        <input type="button" value="test" onclick="myclick();"/>
        <select id="myselect">
              
        </select>
    </div>
    </form>
</body>

posted @ 2011-08-07 21:09  _安静ゝ  阅读(310)  评论(0编辑  收藏  举报