[英]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.