簡體   English   中英

有人輸入時提示文本字段值

[英]alert text field value when someone enters

我有一個文本字段說

<input id="hello" type="text" name="suraj" />

當有人在此字段中輸入值時,是否可以通過javascript或jquery來提醒該值(無需單擊任何按鈕)。

請幫忙。 謝謝

按下按鍵時,您會收到多個警報。 如果處理聚焦,則可以看到鍵入的值。 如果可以處理聚焦,請使用此代碼。

$('#hell').on('focusout', function(){
  alert(event.target.value);
})

您可以使用.keyup()事件,如下所示:-

$('#hell').on('keyup',function(){
   alert($(this).val());
});

小提琴

或者(如果您想在用戶輸入完畢后立即提醒文本,請使用.blur()事件,如圖所示)

$('#hell').on('blur',function(){
  alert($(this).val());   
});

小提琴

或者您也可以使用.focusout()事件,如圖所示

$('#hell').on('focusout',function(){
    alert($(this).val()); 
});

小提琴

這是鍵盤的一些后續事件

http://api.jquery.com/keypress/

http://api.jquery.com/keydown/

http://api.jquery.com/keyup/

並嘗試

$('#hell').on('keyup',function() {
       alert($(this).val());
    });

要么

$('#hell').on('keydown',function() {
       alert($(this).val());
    });

要么

$('#hell').on('keypress',function() {
   alert($(this).val());
});

這樣就可以使用焦點事件。

$('#hell').on('focusout',function(){
   alert($(this).val());
});

或者您可以使用模糊

$('#hell').on('blur',function(){
  alert($(this).val())      
});

您可以使用如下所示的keyup事件

$('#hell').on('keyup',function()
{
   alert($(this).val());
});

請嘗試這個。

 <input id="hell" type="text" name="suraj" onChange="toggle()"/>

    <script language="JavaScript">
        function toggle() {
       var value = document.getElementById('hell').value;
       alert(value);
        }
    </script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM