jQuery संस्करण: 1.4.1jQuery Focusin और लाइव ईवेंट सक्रिय हो रहे focusout
मैं एक साधारण वॉटरमार्क प्रकार प्लगइन लिखने के लिए प्रयास कर रहा हूँ और मैं नहीं के बाद से लाइव ईवेंट का लाभ लेने के सभी तत्वों का चाहते हैं मैं इसका उपयोग पृष्ठ लोड के दौरान मौजूद होगा, या उन्हें डीओएम से जोड़ा और हटाया जा सकता है। हालांकि, किसी कारण से घटनाएं कभी नहीं आग लगती हैं।
; (function($) {
$.fn.watermark = function(text) {
return $(this).each(function() {
$(this).live('focusout', function() {
if (this.value == "") {
this.value = text;
}
return false;
});
$(this).live('focusin', function() {
if (this.value == text) {
this.value = "";
}
return false;
});
});
}
})(jQuery);
मैं इस लाइव ईवेंट का उपयोग किए बिना काम करने के लिए प्राप्त कर सकते हैं:
यहाँ काम नहीं कर कोड है।
; (function($) {
$.fn.watermark = function(text) {
return $(this).each(function() {
$(this).focusout(function() {
if (this.value == "") {
this.value = text;
}
return false;
});
$(this).focusin(function() {
if (this.value == text) {
this.value = "";
}
return false;
});
});
}
})(jQuery);
'$ (this) .each' द्वारा प्रतिस्थापित किया जाना चाहिए' एक ही कारण के लिए this.each'। – jAndy
@jAndy - असल में उसे '.each() 'की आवश्यकता नहीं है, केवल जंजीर चयनकर्ता :) –
कुछ ठीक नहीं लगता है। मैंने सोचा कि आपको हमेशा इस वापसी का उपयोग करना चाहिए? देखें: http://stackoverflow.com/questions/2678185/why-return-this-eachfunction-in-jquery-plugins –