1 回答
TA贡献1825条经验 获得超4个赞
'use strict';
export default function () {
return {
restrict: 'A',
link: function ($scope, $element, $attributes) {
var limit = $attributes.maxlength;
$element.bind('keyup', function (event) {
var element = $($element).closest('.form-group');
element.toggleClass('has-warning', limit - $element.val().length <= 10);
element.toggleClass('has-error', $element.val().length >= limit);
});
$element.bind('keypress', function (event) {
// Once the limit has been met or exceeded, prevent all keypresses from working
if ($element.val().length >= limit) {
// Except backspace
if (event.keyCode !== 8) {
event.preventDefault();
}
}
});
}
};
}
添加回答
举报