考虑这个替代解决方案:
- 使用单个按钮
- 操作.text()和.css()更改按钮属性
- 由于您需要的特殊情况而实现了自定义切换器
这是代码:
CSS:
button { width: 200px; height: 60px; color: white; font-size: 20px; background-color: red; }
HTML:
<button class=''> Mute </button>
JS:
function unmute() {
    $('button').removeClass('muted');
    $('button').text('Unmute');
    $('button').css('background-color','blue');
}
function mute() {
    $('button').addClass('muted');
    $('button').text('Mute');
    $('button').css('background-color','red');
}
function customToggler() {
    if (disableToggle) return;
    if ($('button').hasClass('muted')) unmute(); else mute();
}
var disableToggle = false;
$(document).ready(function() {
    customToggler();
    $('button').click(function() {
       disableToggle = true;
       customToggler();
    });
    $('button').mouseover(function() {  
        customToggler();
    }).mouseout(function() {  
        customToggler();
        disableToggle = false;
    });
});
--
要查看上面的代码,请参阅http://jsfiddle.net/fwjz5/祝你好运!</p>