简体   繁体   English

当用户将光标放在asp.net的文本框中时,我需要发出警报。 我该怎么做呢?

[英]I need to give an alert when the user places the cursor in a textbox in asp.net. How do I go about doing this?

I need to give a custom alert to the user when the user places the cursor in a textbox item in asp.net. 当用户将光标放在asp.net的文本框项中时,我需要向用户提供自定义警报。 How do I go about doing this? 我该怎么做呢? Please help. 请帮忙。

<input type="text" onfocus="alert('Got focus!');"/>

or a bit more involved: 或者更多涉及:

<script>
  function InputFocus()
  {
    var inp = document.getElementById('myInput');
    inp.onfocus = null; 
    alert('Got focus - ' + inp.id);
    setTimeout(function() { inp.onfocus = InputFocus; }, 100);
  }
</script>

<input type="text" value="one"/>
<input id="myInput" type="text" onfocus="InputFocus();" value="two"/>
<input type="text" value="three"/>

Javascript on focus event. 焦点事件的Javascript。

On Page_Load or Page_Init method add this code: 在Page_Load或Page_Init方法上添加以下代码:

 mytextBox.Attributes.Add("onfocus", "enterTextBox();")

Then on the page add a script tag with this : 然后在页面上添加一个脚本标记:

function enterTextBox() {
     alert('hello');
}

the two events that you need are onfocus (elemant has focus and can accept input) and onblur which gets fired when leaving the element (say a text box). 你需要的两个事件是onfocus(elemant有焦点并且可以接受输入)和onblur在离开元素时会被触发(比如一个文本框)。 Disabled elements cannot have focus so these events will not occur in that case. 禁用的元素不能具有焦点,因此在这种情况下不会发生这些事件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在asp.net中将日历与文本框同步。 - How to Synchronise calendar with Textbox in asp.net. asp.net中页面上的多个相同表单。 如何获得变量? - Multiple identical forms on a page in asp.net. How do I get variables? 我如何使用asp.net打印HTML表。 每页的页眉和页脚 - how do i print HTML table using asp.net. Header and footer on each page 我需要使用 C# 和 ASP.Net 构建一个重量非常轻的 Ajax 引擎。 你有什么建议? - I need to build a very light weight Ajax Engine using C# and ASP.Net. What do you suggest? 我如何在asp.net中给消息警报框 - How can i give message alert box in asp.net 在上传到 ASP.NET 中的服务器之前,我需要在客户端机器中检查一个大文件的 MD5。 - I need to check MD5 of a large file in client machine before uploading into server in ASP.NET. 当我单击和双击时,如何给TextBox动态创建的值? vb.net - How do i give a value a TextBox create dynamically when i click and doubleClick? vb.net ASP.NET中的AdWords API。 我可以避免使用`user`对象吗? - AdWords API in ASP.NET. Can I avoid using the `user` object? 如何将IdentityServer3添加到现有的基于ASP.Net Identity的项目中? - How do I go about adding IdentityServer3 to an existing ASP.Net Identity based project? 用户使用JQuery切换到Asp.net文本框值时,如何用它替换以前的asp.net文本框值? - How can I fill an asp.net textbox with a previous asp.net textbox value when the user tabs to it using JQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM