JavaScript: parcourir les états de case à trois états

HTML:
<!-- Inline click handler, just for demo -->
<input type="checkbox" id="cb1" onclick="ts(this)">

JS: 
function ts(cb) { // This should show the states in the following order and cycle through them: checked, indeterminate, off.
  if (cb.readOnly) cb.checked=cb.readOnly=false;
  else if (!cb.checked) cb.readOnly=cb.indeterminate=true;
}
Stehlampe2020