Skip to content

Instantly share code, notes, and snippets.

@takuya
Created December 17, 2014 08:05
Show Gist options
  • Save takuya/66b2b9dabc4ec1fe9a8d to your computer and use it in GitHub Desktop.
Save takuya/66b2b9dabc4ec1fe9a8d to your computer and use it in GitHub Desktop.
タイムズプラスログインのmaxlength.js
/// takuya
// いったい何がしたいの・・・
$(function(){
$('input[maxlength]').each(function(){
var maxlength = $(this).attr('maxlength');
var f = function(){
if($(this).val().length <= maxlength){
$(this).attr('maxlength', maxlength).unbind('keydown keypress keyup focus', f);
}else{
$(this).removeAttr('maxlength');
}
};
$(this).bind('keydown keypress keyup focus', f);
if($(this).val().length <= maxlength){
$(this).attr('maxlength', maxlength);
}else{
$(this).removeAttr('maxlength');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment