jQuery UI按钮 - 如何更改样式和图标选中按钮?

Pit*_*nek 5 jquery jquery-ui

<script type="text/javascript">
    jQuery(document).ready(function($){
        $('.date').datepicker($.datepicker.regional['cs']);
        $(".votePollState").button({ icons: {primary:'ui-icon-closethick'},text: false });
    });
</script>
Run Code Online (Sandbox Code Playgroud)

HTML代码:

<input type="checkbox" class="votePollState" id="point-1"/><label for="point-1">Choice 1</label>

<input type="checkbox" class="votePollState" id="point-1"/><label for="point-1">Choice 1</label>
Run Code Online (Sandbox Code Playgroud)

我需要为复选框状态设置一些图标,没有选中复选框有其他图标,复选复选框有其他.不,如果我选中复选框,这有一些图标,但只更改边框颜色.

有些东西在iPhone上使用ON/OF开关按钮.

谢谢

Nic*_*ver 12

You could add a .change() handler that took the .checked state of the checkbox and assigned the icon based on it, like this:

$(".votePollState").button({ 
    icons: {primary:'ui-icon-closethick'},
    text: false 
}).change(function() {
    $(this).button("option", { 
        icons: { primary: this.checked ? 'ui-icon-check' : 'ui-icon-closethick' }
    });
});
Run Code Online (Sandbox Code Playgroud)

You can test it out here.