2016-03-25 7 views
0

Jqueryを使用してWebアプリケーションを構築しようとしていますが、this.eachを使用している関数を作成してグローバルに宣言しました。 ()と私は希望の結果を得ていない関数の要件を実行しようとしています。私も構文をチェックし、エラーを受けていません。jqueryのthis.each(function())の動作方法

$('[data-nitspagelabel]').click(function() { //click function on editable div to get editable buttons 
      var nitsedit = $(this); 
      var labeltype = $(this).data("nitslabeltype"); 
      if (labeltype == "text") { 
       if (modal == false) { 
        modal = true; 
        $('[data-nitstextbutton]').css({ //popup text editing buttons 
         'top': mouseY 
         , 'left': mouseX 
        }).fadeIn(400).click(function (e) { 
         var popupbox = $(this).attr('href'); 
         openPopup(popupbox); // opens the editing tools popup 
         $(nitsedit).nitspopupeditor; // formatting buttons in action 
         $(nitsedit).attr('contenteditable', 'true'); 
        }); 
       } 
      } 
     }); 

そして、次の私は

$.fn.nitspopupeditor = function() { //Function to format editable items. 
     this.each(function() { 
      setTimeout(function() {}, 100); 
      var $this = $(this); 
      var selected_text = null; 
      var uniquid = "nits" + new Date().getTime(); 

      $this.attr('data-nitsselect', uniquid); //set element unique id 

グローバルに宣言した関数であります私は間違いをしているのか分かりませんが、関数内のものが正しく動作していません。

+0

'あなたの関数内this'は' window'なり、$thisを使用して得ることができますループする? –

+0

あなたは、 '$ .fn.nitspopeditor'の2行目に' this'を 'window'に置き換える必要があることを意味します。 –

+0

それぞれの中の 'this'はeq' window'ではありません。私の最善の知識から、それぞれの内部の「this」は現在のループ値です。 –

答えて

-1

.eachは各繰り返しで配列の各要素をとるイテレータです。あなたは.eachメソッドにここ

ある例は、配列を送信する必要がありますので、現在の要素へ のアクセスは、あなたが何をしようとしている、 http://api.jquery.com/jquery.each/

関連する問題