日期:2014-05-20  浏览次数:20433 次

关于window.showModalDialog问题
问题1
为什么我将TextBox2的Visible   设为false,在运行时就出现如下脚本错误:
‘document.getElementById   (...)’为空或不为对象。
-----------
1.aspx
function   Selectclass()
{
      var   myWin;
myWin=window.showModalDialog( "1.aspx ",   "dialogWidth=300px;dialogHeight=400px ");  
if(myWin!=null)
{
document.getElementById   ( "TextBox1 ").value=myWin[0];
document.getElementById   ( "TextBox2 ").value=myWin[1];
}
}
<asp:TextBox   ID= "TextBox1 "   runat= "server "> </asp:TextBox>
<input   id= "Butselect_class "   type= "button "   value= "选择栏目 "   onclick   = "Selectclass() "   />
<asp:TextBox   ID= "TextBox2 "   runat= "server "   Visible   = "false "   />
============
2.aspx
  string   script   =   " <Script   language= 'javascript '> var   ary   =   new   Array( ' "   +   mycode1   + " ', ' "+mycode2   +   " ');window.returnValue=ary;window.close(); </script> ";
                Response.Write(script);
                Response.End();
------------


==============
==============
问题2
将1.aspx中的TextBox1改为Label1,为什么Label1得不到值?
1.aspx
function   Selectclass()
{
      var   myWin;
myWin=window.showModalDialog( "1.aspx ",   "dialogWidth=300px;dialogHeight=400px ");  
if(myWin!=null)
{
document.getElementById   ( "TextBox1 ").value=myWin[0];
document.getElementById   ( "TextBox2 ").value=myWin[1];
}
}
<asp:TextBox   ID= "TextBox1 "   runat= "server "> </asp:TextBox>
<input   id= "Butselect_class "   type= "button "   value= "选择栏目 "   onclick   = "Selectclass() "   />
<asp:Label   ID= "Label1 "   runat= "server "     > </asp:Label>


------解决方案--------------------
Visible 是服务器端的属性,如果设为false, 客户端的html中就不会有这个元素.