很多时候 为了编程方便、快捷,我们经常定义全局变量 页面加载初始化并赋值

但是在此全局变量为控件对象时:

                  var test;
		$(function ()
		{
			test = document.getElementById("TextBox1");
		});
		function clk()
		{
			alert(test.value);
		}

	<asp:UpdatePanel ID="UpdatePanel1" runat="server">
		<ContentTemplate>
			<div >
				<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
				<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
				<input  />
			</div>
		</ContentTemplate>
	</asp:UpdatePanel>

     protected void Button2_Click(object sender, EventArgs e)
	{
		TextBox1.Text = "abc";
	}

再触发clk()点击事件时 弹出的将会还是空
所以对于控件对象 还是何时用何时getElementByXXX()得好

相关文章:

  • 2021-11-18
  • 2021-11-18
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-05-31
猜你喜欢
  • 2022-12-23
  • 2021-11-18
  • 2021-10-01
  • 2021-09-13
相关资源
相似解决方案