简体   繁体   English

输入更改不起作用时的jQuery触发器

[英]Jquery trigger when input changes not works

I am trying to use Jquery to trigger the event when user change the value in my input. 当用户更改输入中的值时,我尝试使用Jquery触发事件。

It is supposed to be fairly easy, however, I tried all the ways but none of them works for me. 本来应该很容易,但是,我尝试了所有方法,但没有一种对我有用。

Here is my HTML: 这是我的HTML:

<input id="size" type="text" name="Size[mm]" style="width:40px; margin-top:5px; padding-left:10px;" value="1.00" maxlength="6" size="10">

Here are my jQuery: 这是我的jQuery:

I tried: 我试过了:

<script>
$('#size').bind('keyup mouseup change',function(){
       alert('Yeah!');
});
</script>

And

<script>
$("input#size").change(function(){
          alert('Yeah!');
}).change();
  </script>

And

<script>
$("#size").change(function(){
          alert('Yeah!');
});
</script>

However, none of these works and nothin happens in my Firebug.. 但是,我的Firebug中这些工作都没什么,没什么。

Any ideas? 有任何想法吗?

Thanks 谢谢

If they are not working, you are probably adding the event handlers before the element is rendered. 如果它们不起作用,则可能在呈现元素之前添加了事件处理程序。 Use document ready . 准备好使用文档

<script>
    $( function(){
        $('#size').bind('keyup mouseup change',function(){
            alert('Yeah!');
        });
    });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM