检测更改的输入文本框 [英] Detect changed input text box

查看:36
本文介绍了检测更改的输入文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究了许多其他问题,并找到了非常简单的答案,包括下面的代码.我只是想检测何时有人更改了文本框的内容,但由于某种原因它无法正常工作……我没有收到控制台错误.当我在浏览器的change()函数中设置断点时,它永远不会命中它.

I've looked at numerous other questions and found very simple answers, including the code below. I simply want to detect when someone changes the content of a text box but for some reason it's not working... I get no console errors. When I set a breakpoint in the browser at the change() function it never hits it.

$('#inputDatabaseName').change(function () { 
    alert('test'); 
});

<input id="inputDatabaseName">

推荐答案

您可以使用 input Javascript事件:

You can use the input Javascript event in jQuery like this:

$('#inputDatabaseName').on('input',function(e){
    alert('Changed!')
});

在纯JavaScript中:

In pure JavaScript:

document.querySelector("input").addEventListener("change",function () {
  alert("Input Changed");
})

或者像这样:

<input id="inputDatabaseName" onchange="youFunction();"
onkeyup="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();"/>

这篇关于检测更改的输入文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆