admin管理员组文章数量:1291144
The following code does not work on all input elements:
$(':input').on('input', function(){
alert('boom shakalaka');
});
It has no effect on check-boxes even though they are input elements, and checking or unchecking changes its state.
I can add the change
event too inside on()
but then the same event will be fired twice on other input fields.
Is there any reliable input state-change event that is consistent for all form elements?
The following code does not work on all input elements:
$(':input').on('input', function(){
alert('boom shakalaka');
});
It has no effect on check-boxes even though they are input elements, and checking or unchecking changes its state.
I can add the change
event too inside on()
but then the same event will be fired twice on other input fields.
Is there any reliable input state-change event that is consistent for all form elements?
Share Improve this question edited Sep 5, 2019 at 15:34 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 29, 2014 at 17:24 thelolcatthelolcat 11.6k22 gold badges65 silver badges106 bronze badges 7-
It will not fire twice if you will add
change
toon
method – antyrat Commented Jul 29, 2014 at 17:25 - it does, i tested it. for eg. on selects... did you mean "input change" or just "change" ? I cannot use change only bc the event handler has to run for text fields too – thelolcat Commented Jul 29, 2014 at 17:26
-
.on('input change', function () {})
– emerson.marini Commented Jul 29, 2014 at 17:29 - 1 Works only once for me: jsfiddle/84vK7 – antyrat Commented Jul 29, 2014 at 17:30
- @antyrat it triggers twice for the textbox – Saksham Commented Jul 29, 2014 at 17:33
3 Answers
Reset to default 6There is no single event that would be authoritative, but you can bind to multiple events -
$(':input').on('change keyup input', function() {
console.log('changed');
});
P.S. I wanted to give you a +1 for using 'boom shakalaka' in an example, but I digress.
<!--Why not just use onclick ?-->
<!--Ur-->
<script>
$('input#checkbox').on('click', function(){
alert('boom shakalaka');
});
</script>
<input type="checkbox" id="checkbox">
<!--Or-->
<input type="checkbox" onclick="anyfunction();">
I'm not sure if what you want but maybe a simple blur event?
$('input').on('blur',function(e){
alert('event');
});
本文标签: javascriptoninput does not fire on checkboxesStack Overflow
版权声明:本文标题:javascript - oninput does not fire on checkboxes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741505772a2382311.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论