開発メモ

開発用のメモです。

JQuery $(":checkbox").attr("checked", "") で チェックをはずす

<script>
$(document).ready(function(){
   $.fn.origAttr = $.fn.attr;
   $.fn.attr = function(key, value) {
       var keys = [], i = 0;
   
       keys[i++] = "checked";
       keys[i++] = "selected";
       keys[i++] = "requred";
       keys[i++] = "multiple";
       keys[i++] = "readonly";
       keys[i++] = "disabled";
       keys[i++] = "standby";
       keys[i++] = "compact";
       keys[i++] = "declare";
       keys[i++] = "defer";
       keys[i++] = "ismap";
       keys[i++] = "nohref";
       keys[i++] = "noresize";
       keys[i++] = "noshade";
       keys[i++] = "nowrap";
   
       var regexpKeys = "/(" + keys.join("|") + ")/ig";
       if (typeof key == "string") {
           if (key.match(regexpKeys) == null) {
               $(this).origAttr(key, value);
           } else if (value == 0 || !!value) {
               $(this).origAttr(key, value);
           } else {
               $(this).removeAttr(key);
           }
       } else {
           $(this).origAttr(key, value);
       }
       return $(this);
   };
});
</script>
Twitter: @asahina_alice