for (i=1;i<=10;i++)
{
var temp = document.getElementById("<%=DropDownList(i).ClientID%>");
if (temp.options[temp.selectedIndex].text== '请选择')
{
alert("請選擇!");
// document.all.DropDownList(i).focus();
temp.focus();
return false;
}}DropDownList(i) 如果是后台发过来的数据,就不可以这么用。
{
var temp = document.getElementById("<%=DropDownList(i).ClientID%>");
if (temp.options[temp.selectedIndex].text== '请选择')
{
alert("請選擇!");
// document.all.DropDownList(i).focus();
temp.focus();
return false;
}}DropDownList(i) 如果是后台发过来的数据,就不可以这么用。
到客户端这边都是写好了的 到了HTML页面自己看输出有什么规律啊
写成("<%=DropDownList"+i+".ClientID%>")和document.all.DropDownList+i
或者定义变量
for (i=1;i<=10;i++)
{
var drop=DropDownList+i;
("<%=DropDownList(i).ClientID%>")变("<%=drop.ClientID%>")
document.all.DropDownList1 变 document.all.drop
{
var drop=DropDownList+i;
if (document.getElementById("<%=drop.ClientID%>").options[document.getElementById("<%=drop.ClientID%>").options.selectedIndex].text== '请选择')
{
alert("請選擇!");
document.all.drop.focus();
return false;
}}
for (i=1;i <=8;i++)
{
var temp = document.getElementById(" <%=DropDownList"+i+".ClientID%>");
if (temp.options[temp.selectedIndex].text== '请选择')
{
alert("請選擇!");
// document.all.DropDownList(i).focus(); temp.focus(); return false;
} } 都不行
for (i=1;i<=10;i++)
{
o=document.getElementById("DropDownList"+i);
if(o.options[o.selectedIndex=='请选择'){
alert("請選擇!");
o.focus();
return false;
}
}
for (i=1;i<=10;i++)
{
o=document.getElementById("DropDownList"+i);//如果你的服务器控件没有放入客户端控件或者数据控件,如dv中,客户端id和服务器端一样的
if(o.options[o.selectedIndex].text=='请选择'){//=========更正这里
alert("請選擇!");
o.focus();
return false;
}
}