+ -
当前位置:首页 → 问答吧 → 求助,怎样在调用JS函数时传递控件ID?

求助,怎样在调用JS函数时传递控件ID?

时间:2009-08-19

来源:互联网

我想通过DropDownList 的一个change事件调用JS的function,但调用的同时要传递该控件的ID和另外一个控件的ID,请问怎样传递另外一个控件的ID过去?

我的代码是这样的:

function Test(thisControl, otherControl)
{
        //TODO
}

<asp:DropDownList ID="Name"    runat="server" onchange="Test(this, 请问这个地方怎样传递Age 控件 )">  </asp:DropDownList>

这是另外一个控件:<asp:TextBox ID="Age" runat="server" MaxLength="100"></asp:TextBox>。

我知道如果DropDownList 为客户端控件的话可以这样传递两个控件ID,onchange="Test(this, ‘<%=Age.ClientID %>’ )"
但这个是服务器控件我试过了好像不行,请问有没有别的方法?

作者: yorytang   发布时间: 2009-08-19

难道不是 test(this, document.getelementbyid("age"))吗?

或者是 test (this, $("#age"))。"this" is not jquery obj.

作者: jerry.yan.mj   发布时间: 2009-08-20

直接test(this,Age)就可以吧

作者: jackeyhlj   发布时间: 2009-08-20

var otherID = document.getElementById("Age").ID;

test(this,otherID )

试试行吗?

作者: xyq159589   发布时间: 2009-08-20