Utilizzo dello script disattivato http://viralpatel.net/blogs/2008/12/set-maxlength-of-textarea-input-using-jquery-javascript.html Sto cercando di limitare l'input di una textarea a 1000 caratteri. Prototipo è anche incluso nella pagina.Lunghezza massima nell'area di testo con jQuery
Funziona bene in cromo, ma in Firefox è dato il seguente errore e l'ingresso non è limitata:
$("textarea[maxlength]") is null
io sono completamente confusi. Qualsiasi aiuto sarebbe apprezzato. Seguono i frammenti di codice.
textarea:
<%= 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();
}
}
});
}
esatta stessa domanda: - [chiesto da me;)] Si prega di vedere questo. http://stackoverflow.com/questions/1125482/how-to-impose-maxlength-on-textarea-in-html-javascript –
Questa non è affatto la stessa domanda. Ha già una soluzione, ha solo difficoltà a far funzionare la parte jQuery. –
non esattamente _ la stessa domanda. OP sta chiedendo specificatamente a jquery: D – Jared