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