1
이 텍스트 캐터와 리미터는 훌륭하게 작동하지만 "문자 남음"의 표시를 텍스트 영역 이전으로 변경할 수 있기를 바랍니다. 개발자는 전자 메일에 응답하지 않으므로 궁금합니다. 어떻게 텍스트 영역 앞에 남아있는 문자를 표시하도록 변경합니까? 감사합니다 ...이 jQuery 플러그인의 표시를 변경하는 방법은 무엇입니까?
HTML :
<p>Message (less than 1000 characters):</p> (would like the remaining character count to display here)
<script type="text/javascript"> jQuery(function($){ $("textarea.text").dodosTextCounter(1000, {counterDisplayElement: "span",counterDisplayClass: "textCounterDisplay"}); });</script>
<textarea class="text" name="comment" id="comment" rows="10" cols="60"></textarea>
(Character count is now displayed here)
JQuery와 :
이jQuery.fn.dodosTextCounter = function(max, options) {
// if the counter display doesn't exist, the script will attempt to create it
options = $.extend({
counterDisplayElement: "span", // tag for the counter display
counterDisplayClass: "dodosTextCounterDisplay", // class for the counter display
addLineBreak: true // whether to add <br /> after the input element before the counter display
}, options);
$(this).each(function(i) {
updateCounter(this, max, options, i);
$(this).keyup(function() {
updateCounter(this, max, options, i);
return this;
});
});
return this;
};
function updateCounter(input, max, options, index) {
var currentLength = 0;
var val = $(input).val();
if(val) {
currentLength = val.length;
}
if(currentLength > max) {
$(input).val(val.substring(0, max));
} else {
var charLeft = max - currentLength;
var counterDisplay = options.counterDisplayElement + "." + options.counterDisplayClass + ":eq("+index+")";
var createNew = $(counterDisplay).length == 0;
if(createNew) {
var element = document.createElement(options.counterDisplayElement);
if(options.counterDisplayElement == 'input') {
$(element).val(charLeft.toString());
} else {
$(element).html(charLeft.toString());
}
$(element).addClass(options.counterDisplayClass).insertAfter($(input));
if(options.addLineBreak) {
$(input).after("<br />");
}
} else {
if(options.counterDisplayElement == 'input') {
$(counterDisplay).val(charLeft.toString());
} else {
$(counterDisplay).html(charLeft.toString());
}
}
}
}
감사합니다. 나는 너무 당황 스럽다. 나는 그 속성을 바꿀 수 있다는 것을 보았어 야했지만 jQuery를 배우고있다 .... – markratledge