在js中我想实现的功能是,根据函数中传来的控件ID得到textbox文本的值,js函数如下:
function account2(ControlID)

  alert(ControlID);
  var strBeginDate = document.all(ControlID)value;
  alert(strBeginDate);
}
但是象上面那样的写法,得不到值,不知道该怎么写,请高手指点(声明:ControlID已经传过来了,我测试过的)

解决方案 »

  1.   

    写错了,不好意思,代码第二行应该是: var strBeginDate = document.all(ControlID).value; 
      

  2.   

    <input type=text id=ControlID>直接這樣抓就可以了
    var strBeginDate = document.all.ControlID.value; 
      

  3.   

    如果是服务器控件的话就是:
    var strBeginDate = document.getElementById('<%=ControlID.ClientID%>')value;
    一般的客户端控件就是:
    var strBeginDate = document.getElementById('ControlID')value;
      

  4.   

    汗,.value那里忘记打点了,嘿嘿
      

  5.   

    中括号
    function account2(ControlID) 

      alert(ControlID); 
      var strBeginDate = document.all[ControlID].value; 
      alert(strBeginDate); 
      

  6.   

    程序看不出有错!!
    不过你传过去的ControlID,这个ControlID是有value的属性吗??
      

  7.   

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!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>
        <script   language=javascript>
            function a() {
                alert(document.getElementById("TextBox1").value)        }
            function b(obj) {
                alert(document.getElementById(obj).value)        }  
       </script> </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <input id="Button1" type="button" value="button" onclick=b("TextBox1") /></div>
        </form>
    </body>
    </html>
      

  8.   

    ASP.NET服务端生成的控件,在客户端显示的ID和你在服务端指定不一样。
    你可以在页面中点击右键查看源码,就知道你传过去的ControlId是不是ClientId。
    可以使用document.getElementById(ControlId).value获取或设置。