实现中间复选框状态

use*_*075 -1 checkbox materialize

在 Materialise 中取消选中时,如何让复选框显示为“不确定”?

HTML:

<input type="checkbox" id="test" checked/>
<label for="test" id="test-label">Red</label>
Run Code Online (Sandbox Code Playgroud)

JS:

$('#test-label').click(function() {
    var checkbox = $(this).prev();
    if (!$(checkbox).is(':checked'))
        $(checkbox).prop('indeterminate', true);
});
Run Code Online (Sandbox Code Playgroud)

https://jsfiddle.net/Lhwkfb75/8/

Yas*_*tav 5

它应该indeterminate代替intermediate. 由于它们的拼写相似,您可能会感到困惑。

$('#test').click(function() {
    if (!$(this).is(':checked'))
        $(this).prop('indeterminate', true);
});
Run Code Online (Sandbox Code Playgroud)