Использование сценария off http://viralpatel.net/blogs/2008/12/set-maxlength-of-textarea-input-using-jquery-javascript.html Я пытаюсь ограничить ввод текстовой области до 1000 символов. Прототип также включен в страницу.
Отлично работает в chrome, но в firefox выдается следующая ошибка и ввод не ограничен:
$("textarea[maxlength]") is null
Я полностью в тупике. Любая помощь будет оценена. Ниже приведены фрагменты кода.
Текстовая область:
<%= text_area 'project', 'description', 'cols' => 60, 'rows' => 8, 'maxlength' => 1000 %>
JavaScript:
<%= javascript_include_tag "jquery", "jquery.maxlength" -%>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function($) {
$().maxlength();
})
</script>
jquery.maxlength.js:
jQuery.fn.maxlength = function(){
$('textarea[maxlength]').keypress(function(event){
var key = event.which;
//all keys including return.
if(key >= 33 || key == 13) {
var maxLength = $(this).attr('maxlength');
var length = this.value.length;
if(length >= maxLength) {
event.preventDefault();
}
}
});
}