【发布时间】:2011-08-10 18:21:15
【问题描述】:
好的,所以我在多视图内的页面上有多个 ASP 文本框和 ASP 按钮。 只有在文本框中输入了文本时,才应启用与每个文本框关联的提交按钮。所以,我写了一个 Javascript 函数来处理这个问题,我收到一条错误消息 "document.getElementById(...)' is null or not an object"
function checkEmptyTxtBox(val, savebtn) {
if (val.value.replace(/^\s+|\s+$/g, "") == "")
document.getElementById(savebtn).disabled = true;
else
document.getElementById(savebtn).disabled = false;
}
<asp:TextBox
ID="txt_Comments_2"
runat="server"
Wrap="true"
TextMode="MultiLine"
onkeyup="checkEmptyTxtBox(this,'<%= btnSave2.ClientID %>')">
</asp:TextBox>
<asp:Button
ID="btnSave2"
runat="server"
text="Save"
Enabled="False"/>
这是在 VS2010 上。
【问题讨论】:
-
你为什么不简单地使用RequiredFieldValidator?
-
因为在启用保存按钮时文本框可以为空的场景。
标签: javascript asp.net visual-studio-2010