![](/img/trans.png)
[英]How to get the input text value in jquery from handlebar page when user enters data in input field?
[英]alert text field value when someone enters
我有一個文本字段說
<input id="hello" type="text" name="suraj" />
當有人在此字段中輸入值時,是否可以通過javascript或jquery來提醒該值(無需單擊任何按鈕)。
請幫忙。 謝謝
按下按鍵時,您會收到多個警報。 如果處理聚焦,則可以看到鍵入的值。 如果可以處理聚焦,請使用此代碼。
$('#hell').on('focusout', function(){
alert(event.target.value);
})
這是鍵盤的一些后續事件
http://api.jquery.com/keypress/
http://api.jquery.com/keydown/
並嘗試
$('#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.