The jQuery .on() and .trriger() methods provide a way to bind and fire multi handlers on one single element by specifying event.namespace, without disturbing each other.
However, I found namespace is not working for checkbox, it just fires all the bound handlers which are attached in different namespaces.
The code is very simple, something like:
$('checkbox').on('click.n1',func1).on('click.n2',func2);
$('checkbox').trigger('click.n1');
Both func1
and func2
would be fired. The same code works fine on other elements.
Is it a BUG? Or did I miss anything for checkboxex?
Thank you for any help!
foo();
function foo() {
$("#checks input")
.on('click.checks1',function(){console.log('click.checks1')})
.on('click.checks2',function(){console.log('click.checks2')});
$("#checks input").eq(0)
.trigger('click.checks1');
$("#radios input")
.on('click.radios1',function(){console.log('click.radios1')})
.on('click.radios2',function(){console.log('click.radios2')});
$("#radios input").eq(0)
.trigger('click.radios1');
}
<script src="http://ift.tt/1oMJErh"></script>
<div id='checks'>
<input type='checkbox' />1
<br>
<input type='checkbox' />2
<br>
</div>
<div id='radios'>
<input type='radio' />1
<br>
<input type='radio' />2
<br>
</div>
Aucun commentaire:
Enregistrer un commentaire