[英]KeyPress Event of TextBox in ASP.NET
I'm trying to get KeyPress Event for TextBox in ASP.NET, so I found this script, but it does not works for me 我正在尝试在ASP.NET中获取TextBox的KeyPress事件,所以我找到了此脚本,但它不适用于我
<title></title>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript" lang="js">
$(function () {
$("#<%=TextBox1.ClientID %>").keypress(function () {
alert("Wow; Its Work!.")
});
});
</script>
</head>
your script is working very well the problem might be in jquery file its not found in the given location you can change the src for check 您的脚本运行良好,问题可能出在jquery文件中,但在给定位置找不到,您可以更改src进行检查
<script src="jquery.js" type="text/javascript"></script>
To 至
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
try this 尝试这个
<asp:TextBox ID="TextBox1" runat="server" onkeypress="myFunction()"></asp:TextBox>
<script language="javascript">
function myFunction()
{
alert('Key Press')
}
</script>
Like Mostafa wrote, it is important to insert the script at the END of the page. 就像Mostafa所写的一样,将脚本插入页面的末尾很重要。 So that the page can register the controls first. 使页面可以首先注册控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.