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
グローバルに宣言した関数であります私は間違いをしているのか分かりませんが、関数内のものが正しく動作していません。
'あなたの関数内this'は' window'なり、
$this
を使用して得ることができますループする? –あなたは、 '$ .fn.nitspopeditor'の2行目に' this'を 'window'に置き換える必要があることを意味します。 –
それぞれの中の 'this'はeq' window'ではありません。私の最善の知識から、それぞれの内部の「this」は現在のループ値です。 –