我想通过DropDownList 的一个change事件调用JS的function,但调用的同时要传递该控件的ID和另外一个控件的ID,请问怎样传递另外一个控件的ID过去?我的代码是这样的:function Test(thisControl, otherControl)
{
        var age=document.getElementById("otherControl");
}<asp:DropDownList ID="Name" runat="server" onchange="Test(this, 请问这个地方怎样传递Age控件ID)">  </asp:DropDownList>另外一个控件:<asp:TextBox ID="Age" runat="server" MaxLength="100"></asp:TextBox>。

解决方案 »

  1.   

    没明白啥意思,直接写ID,不就得了<asp:DropDownList ID="Name" runat="server" onchange="Test(this, 'Age', 'Age2')">  </asp:DropDownList>function Test(thisControl, otherControl, otherControl2)
    {
            var age=document.getElementById(otherControl);
            var age2=document.getElementById(otherControl2);
      

  2.   

    我也没看明白..直接document.getElementById('age').id 
    不就完了嘛..
      

  3.   

    直接写哦,如果不行,用eval试试。
      

  4.   

    上面的方法都试过了,不行onchange="Test(this, 'Age')">  function Test(thisControl,otherControl)
    {
         var a=document.getElementById("otherControl");
         alert(a);
         //返回为 null     var b=document.getElementById(otherControl);
         alert(b);
         //返回为 null
    }document.getElementById('age').id 这个写法是错误的。
      

  5.   

    代码如下,返回正常
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Test.WebForm4" %><!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="Name" runat="server" onchange="Test(this, 'Age')">
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
            </asp:DropDownList>
            另外一个控件:
            <asp:TextBox ID="Age" runat="server" MaxLength="100"> </asp:TextBox>
        </div>
        </form>
    </body>
    <script type="text/javascript">
        function Test(thisControl, otherControl) {
            var a = document.getElementById("otherControl");
            alert(a);
            //返回为 null        var b = document.getElementById(otherControl);
            alert(b.id);
            //返回为正常 "Age"
        } 
    </script>
    </html>
      

  6.   


    <script type="text/javascript">
    function test(controlId, minGradeId) {
                var a = document.getElementById("minGradeId");
                alert(a); //返回为 null
                            
                var b = document.getElementById(minGradeId);
                alert(b.id); //什么都没弹出来
    </script>
    <asp:DropDownList ID="RelevantSubject01" runat="server" onchange="test(this,'Age')">
    <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
    </asp:DropDownList>
    <asp:TextBox ID="Age" runat="server" MaxLength="100"> </asp:TextBox>很奇怪啊,为什么用第二个方法就没用啊?
      

  7.   

    document.getElement("<%=GridView1.ClientID");或者$get("ID")