Skip to content

Instantly share code, notes, and snippets.

@ledsun
Created June 29, 2012 02:06
Show Gist options
  • Save ledsun/3015221 to your computer and use it in GitHub Desktop.
Save ledsun/3015221 to your computer and use it in GitHub Desktop.
jQueryオブジェクトの属性操作
/*globals define */
/*
* jQuery checkAttr 0.0.1
*
* 属性操作用のメソッドを追加します。
* Licensed under the MIT (MIT-LICENSE.txt)
*
*/
define([
], function () {
$.fn.checkAttr = function (attrName, bool) {
if (bool === undefined) { //第二引数が指定されなかったら
return $(this).attr(attrName) === attrName;
}
return this.each(function () {
if (bool) {
$(this).attr(attrName, attrName);
} else {
$(this).removeAttr(attrName);
}
});
};
});
/*globals define */
/*
* jQuery checked 0.0.1
*
* checked属性操作用のメソッドを追加します。
* Licensed under the MIT (MIT-LICENSE.txt)
*
*/
define([
'common/jquery.checkAttr'
], function () {
$.fn.checked = function (bool) {
return $(this).checkAttr('checked', bool);
};
});
/*globals define */
/*
* jQuery disabled 0.0.1
*
* disabled 属性操作用のメソッドを追加します。
* Licensed under the MIT (MIT-LICENSE.txt)
*
*/
define([
'common/jquery.checkAttr'
], function () {
$.fn.disabled = function (bool) {
return $(this).checkAttr('disabled', bool);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment