首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

DropDownList用在javescript中的有关问题(顶者有分)

2012-01-19 
DropDownList用在javescript中的问题(顶者有分)?向各位请教个问题,是这样的,我的ASP.NET页面上有32个子Dri

DropDownList用在javescript中的问题(顶者有分)?
向各位请教个问题,是这样的,我的ASP.NET页面上有32个子DripDownList控件,在我击一个html 的控件button1时,我想让这32个DripDownList控件都同时绑定到它们各自的第2项,因为我想在我点击button1时不刷新页面,因此我用的是html控件,然后我在button1的点击事件中写了下面事件:
<script type="text/javascript" language="javascript" >
   
  function Button1_onclick() 
{
  var inputs=document.getElementsByTagName('asp:DropDownList');
  for(var i=0;i<32;i++)
  inputs[i].selectedindex=1;//这一行老是出错.
   
 }
 </script>
不过运行时,老是在inputs[i].selectedindex=1;这一行上出错,到底这一行该怎么写呢?
inputs[i].后面应该是什么呢?
请知道的告诉我一声,小弟先在此谢谢各位了

[解决办法]
你试试下面的代码

HTML code
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!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 type="text/javascript">    function setList(){        var lists=document.getElementsByTagName("select");        for(var i=0;i<lists.length;i++){            lists[i].selectedIndex=1;        }    }    </script></head><body>    <form id="form1" runat="server">    <div>        <asp:DropDownList ID="DropDownList1" runat="server">        <asp:ListItem Value="1" Text="1" />        <asp:ListItem Value="2" Text="2" />        <asp:ListItem Value="3" Text="3" />        <asp:ListItem Value="4" Text="4" />        </asp:DropDownList>        <asp:DropDownList ID="DropDownList2" runat="server">        <asp:ListItem Value="1" Text="1" />        <asp:ListItem Value="2" Text="2" />        <asp:ListItem Value="3" Text="3" />        <asp:ListItem Value="4" Text="4" />        </asp:DropDownList>        <asp:DropDownList ID="DropDownList3" runat="server">        <asp:ListItem Value="1" Text="1" />        <asp:ListItem Value="2" Text="2" />        <asp:ListItem Value="3" Text="3" />        <asp:ListItem Value="4" Text="4" />        </asp:DropDownList>        <input id="Button1" type="button" value="button" onclick="setList()" />    </div>    </form></body></html> 

热点排行