2010-12-16 14 views
1

ここに私のコードですが、私はこのコードを理解することができません。 plzは私に次のコードを説明することができます

$('.maxlength') 

    .after("<span></span>") 

    .next() 

    .hide() 

    .end() 

    .keypress(function(e) { 

     var current = $(this).val().length; 

     if (current >= 130) { 

      if (e.which != 0 && e.which != 8) { 

       e.preventDefault(); 

      } 

     } 

     $(this).next().show().text(130 - current); 

    }); 
+0

これを行うには、ちょっと恐ろしい方法です。このコードを使用しないでください! –

+1

@paxdiablo:私のコードはmeeによって書かれていないことを意味します..もし私がこのことを知っていれば、どうすれば助けを求めることができますか..可能ならばコメントをしてはいけません..ごめんなさい、ありがとうございます – Mihir

+0

私はあなた、すでに他人が開発したコード... – kobe

答えて

6
$('.maxlength') // select all items with class 'maxlength' 

.after("<span></span>") // insert a span after 

.next() // move to the span 

.hide() // hide the span 

.end() // go back to originally selected element 

.keypress(function(e) { // add a keypress event handler function 

    var current = $(this).val().length; // get the length of the input value (a string) 

    if (current >= 130) { //if it's long 

     if (e.which != 0 && e.which != 8) { // and if certain keys weren't pressed (delete?) 

      e.preventDefault(); // don't do what those keys would normally do - i.e. ignore the keypress 

     } 

    } 

    $(this).next().show().text(130 - current); // show the remaining chars in the newly added span 

}); 

を助ける...ので、基本的には、このコードは、テキスト領域は、130文字の文字制限がありますし、あなたが入力することができますどのように多くのより多くを示しています。

+0

あまりにもありがとう兄弟..だからここ()は現在の要素を停止し、前の権利に行くことを意味します! end()を使用すると以前のものか元のものかになりますか? – Mihir

+0

@Mihir:http://api.jquery.com/end/:*最新のフィルタリング操作を現在のチェーンで終了し、一致する要素のセットを以前の状態に戻します。* –

+0

ありがとうございます – Mihir

関連する問題