Article View: pl.comp.lang.javascript
Article #51610Re: newbie: problem z keyup() z jQuery
From: zpksoft
Date: Sun, 22 Nov 2015 13:03
Date: Sun, 22 Nov 2015 13:03
46 lines
3463 bytes
3463 bytes
W dniu sobota, 21 listopada 2015 16:42:53 UTC+1 użytkownik jivan...@poczta.onet.pl napisał:
> Uczę się JavaScriptu. Na razie jestem kiepski. Mam na formularzu (nazwanym formName) pole textarea (nazwane 'Opis:') i chciałbym żeby użytkownik miał informację ile znaków może jeszcze wprowadzić. Robię to tak (używam jQuery na stronie bo jest mi potrzebne do innych rzeczy):
>
> $('form#' + formName + ' textarea#message').keyup(function () { return onKeyUpAtTextArea('contact', 'message'); });
> ...
> function maxLengthOfArea(textarea, counter) {
> if (textarea.getAttribute('maxlength') >= textarea.value.length) {
> counter.innerHTML = textarea.getAttribute('maxlength') - textarea.value.length;
> return true;
> }
> return false;
> }
> ...
> function onKeyUpAtTextArea(controller, elemId) {
> 'use strict';
> var formName = getCurrentFormName(controller);
> var currentForm = getCurrentForm(controller);
> var textarea = getFormElement(currentForm, elemId);
> var counter = $('form#' + formName + ' span#' + elemId + '_left')[0];
> return maxLengthOfArea(textarea, counter);
> }
>
> Problem w tym, że funkcja onKeyUpAtTextArea nie jest wołana przy naciskaniu klawisza w polu textarea. Debuggując JavaScript zauważyłem, że przy wykonywaniu kodu jQuery:
>
> // Handle event binding
> jQuery.fn[ name ] = function( data, fn ) {
> return arguments.length > 0 ?
> this.on( name, null, data, fn ) :
> this.trigger( name );
> };
>
> mam:
>
> fn == /\r?\n/g
> data == "ReferenceError: data is not defined"
> name == ""
> jQuery.fn.name == undefined
>
> Czy to może być przyczyną tego że onKeyUpAtTextArea nie jest wywoływana?
> Rozwiązanie mi działało, ale po przerobieniu strony na responsywną przestało działać.
> Jak rozwiązać problem?
Ala nakomplikowane, aż mi się nie chce czytać :)
Raczej nie onkeyUp tylko onChange kontrolki. I po co to całe JQuery?
Paweł
Technical Details
Message-ID:
<708d7a2a-8fe4-4ecc-bf80-f9985d2c04a3@googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin3!goblin.stu.neva.ru!news.ripco.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!mv3no603503igc.0!news-out.google.com!z49ni733qgd.1!nntp.google.com!b51no1351616qgf.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mailReferences:
<d8bb1c55-aa00-4bbb-bb65-862e4f875852@googlegroups.com>Show Full Headers
Complete Article Headers
X-Received: by 10.66.138.74 with SMTP id qo10mr17879942pab.22.1448197388905; Sun, 22 Nov 2015 05:03:08 -0800 (PST) X-Received: by 10.140.93.51 with SMTP id c48mr222791qge.0.1448197388652; Sun, 22 Nov 2015 05:03:08 -0800 (PST) Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin3!goblin.stu.neva.ru!news.ripco.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!mv3no603503igc.0!news-out.google.com!z49ni733qgd.1!nntp.google.com!b51no1351616qgf.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: pl.comp.lang.javascript Date: Sun, 22 Nov 2015 05:03:08 -0800 (PST) In-Reply-To: <d8bb1c55-aa00-4bbb-bb65-862e4f875852@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.21.244.119; posting-account=8ND_mgoAAAD5J9y9fnaTB1Kcu7xKWk7Q NNTP-Posting-Host: 83.21.244.119 References: <d8bb1c55-aa00-4bbb-bb65-862e4f875852@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <708d7a2a-8fe4-4ecc-bf80-f9985d2c04a3@googlegroups.com> Subject: Re: newbie: problem z keyup() z jQuery From: zpksoft <zpksoft@op.pl> Injection-Date: Sun, 22 Nov 2015 13:03:08 +0000 X-Received-Bytes: 3290 X-Received-Body-CRC: 2568797522 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit