Materialize 不改变 :checkbox 的状态

使用如下代码

$(':checkbox').click(function() {
  var obj = $(this);
  var val = (obj.attr('checked') == 'checked');
  if (val) {
    obj.removeAttr('checked');
  } else {
    obj.attr('checked', true);​
  }​
}​

或编写成jQuery扩展

(function($) {
    $.fn.extend({
        MUICheckbox: function(options) {
            this.each(function() {
                if (options.checked) {
                    $(this).attr('checked', true);
                } else {
                    $(this).removeAttr('checked');
                }
            };
            return this;
        }
    });
}) (jQuery);

results matching ""

    No results matching ""