Created
November 6, 2012 23:56
-
-
Save yannmadeleine/4028544 to your computer and use it in GitHub Desktop.
truncated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> | |
</head> | |
<body> | |
<form action=""> | |
<input type="password" name="" id="pwd" maxlength="5" /> | |
<input type="submit" value="Submit"> | |
</form> | |
<script type="text/javascript"> | |
var pasted = function(){ | |
var self = $(this); | |
var length = parseInt(self.attr('maxlength')); | |
self.data('orc-maxlength',length); | |
self.attr('maxlength',length + 1); | |
setTimeout(postPaste,500); | |
}; | |
var postPaste = function(){ | |
var self = $('#pwd'); | |
var length = self.data('orc-maxlength'); | |
self.removeData('orc-maxlength'); | |
self.attr('maxlength', length); | |
if(self.val().length > length ){ | |
console.log('truncated'); | |
} | |
}; | |
$('#pwd').bind('paste',pasted); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment