现在,我有以下内容:
<script>
$('#nav-close').on('click', function(){
var mover = $('#mover');
// register is not visible
if(mover.css('opacity') === '1'){
mover.css({'opacity': '0'});
} else {
mover.css({'opacity': '1'});
}
});
$('#nav-expander').on('click', function(){
var mover = $('#mover');
// register is not visible
if(mover.css('opacity') === '1'){
mover.css({'opacity': '0'});
} else {
mover.css({'opacity': '1'});
}
});
</script>
我如何将两者结合为一体-如下所示的逻辑,以获得更高效的脚本:
$('#nav-close' || '#nav-expander').on('click', function(){
...
最佳答案
用,
代替||
。请参考jquery multiple selector documentation
$('#nav-close,#nav-expander').on('click', function() {
var mover = $('#mover');
// register is not visible
if (mover.css('opacity') === '1') {
mover.css({
'opacity': '0'
});
} else {
mover.css({
'opacity': '1'
});
}
});