环境: VS.NET 2003 C# asp.net v1.1程序:想用JS比较两个DropDownList选择项的索引值,如果ddl1.SelectedIndex > ddl2.SelectedIndex 则显示一个提示标签,否则隐藏该标签。问题:Microsoft JScript 运行时错误: 对象不支持此属性或方法。代码:
.cs:
在Page_Load()中:
// 在客户端返回控件ID
Page.RegisterStartupScript( "start",
"function getDDL1()\n" +
"\n<script>\n" +
" return document.forms(0).item('" + this.ClientID + ":" + this.DDL1.ID + "');\n" +
"}\n" +
"function getDDL2()\n" +
"{\n" +
" return document.forms(0).item('" + this.ClientID + ":" + this.DDL2.ID + "');\n" +
"}\n" +
"</script>\n");//添加事件
DDL2.Attributes.Add("onclick", "CheckIcType()" );
下面是aspx页面JS代码:
<script language="javascript">
function CheckIcType()
{
if ( document.getElementByID(getIcTypeFrom()).SelectedIndex > document.getElementByID(getIcTypeTo()).SelectedIndex )
getLblIcType().visible = true;
else
getLblIcType().visible = false;
}
</script>
请问应该怎么修改?
谢谢!!
.cs:
在Page_Load()中:
// 在客户端返回控件ID
Page.RegisterStartupScript( "start",
"function getDDL1()\n" +
"\n<script>\n" +
" return document.forms(0).item('" + this.ClientID + ":" + this.DDL1.ID + "');\n" +
"}\n" +
"function getDDL2()\n" +
"{\n" +
" return document.forms(0).item('" + this.ClientID + ":" + this.DDL2.ID + "');\n" +
"}\n" +
"</script>\n");//添加事件
DDL2.Attributes.Add("onclick", "CheckIcType()" );
下面是aspx页面JS代码:
<script language="javascript">
function CheckIcType()
{
if ( document.getElementByID(getIcTypeFrom()).SelectedIndex > document.getElementByID(getIcTypeTo()).SelectedIndex )
getLblIcType().visible = true;
else
getLblIcType().visible = false;
}
</script>
请问应该怎么修改?
谢谢!!
上面发的代码乱了,下面的才是:
环境: VS.NET 2003 C# asp.net v1.1程序:想用JS比较两个DropDownList选择项的索引值,如果ddl1.SelectedIndex > ddl2.SelectedIndex 则显示一个提示标签,否则隐藏该标签。问题:Microsoft JScript 运行时错误: 对象不支持此属性或方法。代码:
.cs:
在Page_Load()中:
// 在客户端返回控件ID
Page.RegisterStartupScript( "start",
"function getDDL1()\n" +
"\n<script>\n" +
" return document.forms(0).item('" + this.ClientID + ":" + this.DDL1.ID + "');\n" +
"}\n" +
"function getDDL2()\n" +
"{\n" +
" return document.forms(0).item('" + this.ClientID + ":" + this.DDL2.ID + "');\n" +
"}\n" +
"function getLabel1()\n" +
"{\n" +
" return document.forms(0).item('" + this.ClientID + ":" + this.Label1.ID + "');\n" +
"}\n" +
"</script>\n");//添加事件
DDL2.Attributes.Add("onclick", "CheckIcType()" );
下面是aspx页面JS代码:
<script language="javascript">
function CheckIcType()
{
if ( document.getElementByID(getDDL1()).SelectedIndex > document.getElementByID(getDDL2()).SelectedIndex )
getLabel1().visible = true;
else
getLabel1().visible = false;
}
</script>
请问应该怎么修改?
谢谢!!
TO: Jinglecat我改了,可还是出错哦:
Microsoft JScript 运行时错误: 对象不支持此属性或方法
调试时在下面这行JS代码停止了:
if ( document.getElementByID(getDDL1()).SelectedIndex > document.getElementByID(getDDL2()).SelectedIndex )
if ( getDDL1().selectedIndex > getDDL2().selectedIndex )
// OR
if ( document.getElementByID('<% =DDL1.ClientID %>').selectedIndex >
document.getElementByID('<% =DDL2.ClientID %>').SelectedIndex )