jquery - javascript scope issue -


कोड स्निपेट निम्नानुसार है:

  $ (this) .parents ('td: first '।) .next () लगता है (' विकल्प ') customizeMenu (।' myMenu2 ');  

यह काम करता है, लेकिन:

  var श्रोता = समारोह () {$ (this) .parents ('td: first')। Next () .find ( 'विकल्प') customizeMenu ( 'myMenu2')। }; श्रोता ();  

काम नहीं कर रहा है, क्यों और कैसे इसे ठीक करें?

'यह' एक समारोह में डालते समय एक ही ऑब्जेक्ट को इंगित नहीं करता है, यह वर्तमान फ़ंक्शन को इंगित करता है (आपके मामले में 'श्रोता')। इसके बजाय एक पैरामीटर के रूप में इसे ले लें, यदि वह एक विकल्प है (यह आप पर निर्भर करता है कि आप अपने फ़ंक्शन को कैसे कहते हैं)।

  var listener = function (obj) {$ (obj) .parents ('td : पहले '।।) अगले () लगता है (' विकल्प myMenu2 ');') customizeMenu (। ' }; श्रोता (this);  

Comments

Popular posts from this blog

iphone - How do I make a UIPickerView in a UIActionSheet -

java - Is there an object like a "Set" that can contain only unique string values, but also contain a count on the number of occurrences of the string value? -