jQuery-更改输入文本 [英] jQuery - on change input text
问题描述
我正在尝试创建一个将在text input field
的值更改时执行的函数.单击表单元格(而不是在keyup
上)或粘贴时,该字段的值将更改.我这样尝试过:
I am trying to make a function which will execute when the value of a text input field
is changed. The value of the field changes when a table cell is clicked, not on keyup
, nor paste. I tried it like this:
$("#kat").change(function(){
alert("Hello");
});
我有文本字段:
<input type="text" id="kat" value="0"/>
但是它不起作用.有什么帮助吗?
but it isn't working. Any help?
推荐答案
这是来自jQuery文档页面上的评论:
This is from a comment on the jQuery documentation page:
在较旧的HTML5之前的浏览器中,键"绝对是您想要的.
In older, pre-HTML5 browsers, "keyup" is definitely what you're looking for.
在HTML5中,有一个新事件"input",其行为与您似乎认为"change"应该发生的行为完全相同,因为一旦按下键以将信息输入表单,该事件就会触发.
In HTML5 there is a new event, "input", which behaves exactly like you seem to think "change" should have behaved - in that it fires as soon as a key is pressed to enter information into a form.
$('element').bind('input',function);
$('element').bind('input',function);
这篇关于jQuery-更改输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!