繁体   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?

当用户将光标放在asp.net的文本框项中时,我需要向用户提供自定义警报。 我该怎么做呢? 请帮忙。

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

或者更多涉及:

<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。

在Page_Load或Page_Init方法上添加以下代码:

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

然后在页面上添加一个脚本标记:

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

你需要的两个事件是onfocus(elemant有焦点并且可以接受输入)和onblur在离开元素时会被触发(比如一个文本框)。 禁用的元素不能具有焦点,因此在这种情况下不会发生这些事件。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM