javascript 如何访问 ASP 控件

来源:百度知道 编辑:UC知道 时间:2024/06/16 20:45:02
声明ASP控件代码如下:
<asp:TextBox ID="txt_Name" runat="server" Width="167px"></asp:TextBox>

ASP按钮控件代码如下
<asp:Button ID="Button1" runat="server" Text="提 交" Width="98px" OnClientClick='return CheckInput()' /></td>

jiavascript 代码如下:
<script language=javascript>
function CheckInput()
{
if(document.getElementById("txt_Name").value == "")
{
alert("用户名不能为空!"); return false;
}
return true;
}
</script>

已确认单击按钮正确调用函数CheckInput(),但 if 判断无效。好像找不到控件。什么地方错了?
id完全正确,document.all("txt_Name").value 仍无效。

把你的代码试了一下 可以运行的,你再检查一下

document.all("txt_Name").value试试看,另外最好到输出的html里面看下具体生成的html代码中button的准确id