我想通过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>。
{
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>。
{
var age=document.getElementById(otherControl);
var age2=document.getElementById(otherControl2);
}
不就完了嘛..
{
var a=document.getElementById("otherControl");
alert(a);
//返回为 null var b=document.getElementById(otherControl);
alert(b);
//返回为 null
}document.getElementById('age').id 这个写法是错误的。
<%@ 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>
<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>很奇怪啊,为什么用第二个方法就没用啊?