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

.net中用javascript怎么获取服务器端控件呀
<form   id= "form1 "   runat= "server ">
    <div>
  <input   id= "Checkbox1 "   type= "checkbox "   />
  <asp:Label   ID= "Label1 "   runat= "server "   Text= "222 "> </asp:Label>
  <asp:Label   ID= "Label3 "   runat= "server "   Text= "222333 "> </asp:Label> </div>
  <div>
    <input   id= "Checkbox2 "   type= "checkbox "   />
  <asp:Label   ID= "Label2 "   runat= "server "   Text= "bbbb。。。 "> </asp:Label>
        <asp:Label   ID= "Label4 "   runat= "server "   Text= "222333 "> </asp:Label>
  </div>
        </form>
我点击checkbox   怎么获取Label的值呀

------解决方案--------------------
document.getElementById
------解决方案--------------------
楼上正解

document.getElementById( "label1 ")..

------解决方案--------------------
。。。。 还要有命名空间吧?不清楚,你先预览看一下 控件名称是什么了。
不过javascript可以改变控件的值,不能改变ViewState的值的了。提交表单的时候,服务器控件的值是在viewstate里面的
------解决方案--------------------
document.getElementById( "label1 ").value
------解决方案--------------------
document.getElementById( "Label1 ").value
------解决方案--------------------
document.getElementById( 'Label1 ').innerHTML
------解决方案--------------------
JavaScript前台取后台ASP.NET服务器控件的值
document.getElementById( " <%=服务器控件ID名.ClientID %> ")

示例:document.getElementById( " <%=TextBox1.ClientID %> ")