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