我不明白我的代码出了什么问题。这是非常基本的,但仍然存在错误。
在标题标签中,我有以下脚本,您可以跳过对最后一个函数的注意,这是我这个问题需要的函数:
<script type="text/javascript">
function allowOnlyNumber(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
return false;
return true;
}
function checkboxalert() {
var active = document.getElementById("chkActive").checked;
var inactive = document.getElementById("chkInactive").checked;
if ((!active) && (!inactive)) alert("Please ensure that either Active or Inactive is checked before limiting search, otherwise, Active records will be assumed...")
}
function lostfocusLowPrice() {
if (getElementById("txtFindHighPrice").value = "" && getElementById("txtFindLowPrice").Value != "") getElementById("txtFindLowPrice").Value = getElementById("txtFindLowPrice").Value;
}
</script>
在我的网页设计中,我有这个:
<asp:TextBox ID="txtFindLowPrice" OnTextChanged="lostfocusLowPrice()" onkeypress="return allowOnlyNumber(event)" runat="server" Height="22px" Width="63px"></asp:TextBox>
我收到编译错误:
说明:编译处理此请求所需的资源时出错。请查看以下特定错误详细信息并相应地修改源代码。
编译器错误消息:CS1061:"webform1_aspx"不包含"lostfocusLowPrice"的定义,并且找不到接受类型为"webform1_aspx"的第一个参数的扩展方法"lostfocusLowPrice"(是否缺少 using 指令或程序集引用?
拼写匹配。 代码是非常基本的。 无法想象它可能是什么。 其他JavaScript函数工作正常。
有什么想法吗?
OnTextChanged 事件是一个服务器端事件,所以这里它.cs文件中搜索 lostfocusLowPrice 方法并抛出上述错误。以了解有关 OnTextChanged 事件的更多信息。请参考以下链接。https://meeraacademy.com/textbox-autopostback-and-textchanged-event-asp-net/
下面还有一个:ASP 文本框调用 JavaScript 函数