संपादित करने के लिए मैं jQuery (V.6.1) कोर में 'attr' फ़ंक्शन को संशोधित करने का प्रयास कर रहा हूं।jquery function
मेरे पास एक plugins.js फ़ाइल है जो jquery-6.1.js फ़ाइल के बाद पृष्ठ में शामिल है। Plugins.js फ़ाइल में कुछ एसवीजी कार्यक्षमता को समायोजित करने के लिए विभिन्न jQuery कोर फ़ंक्शंस में किए गए सुधार शामिल हैं।
मैंने attr फ़ंक्शन को plugins.js फ़ाइल में संशोधित किए बिना कॉपी किया है, लेकिन अब इसे जावास्क्रिप्ट त्रुटि उत्पन्न होने पर उत्पन्न होता है।
क्या किसी को पता है कि क्यों इस विशेष समारोह ओवरराइट किया जा करने के लिए पसंद नहीं है (मैं शायद गलत तरीके से उसे ओवरराइट कर रहा हूँ):
(function($){
$.fn.attr = function(elem, name, value, pass){
var nType = elem.nodeType;
// don't get/set attributes on text, comment and attribute nodes
if (!elem || nType === 3 || nType === 8 || nType === 2) {
return undefined;
}
if (pass && name in jQuery.attrFn) {
return jQuery(elem)[ name ](value);
}
// Fallback to prop when attributes are not supported
if (!("getAttribute" in elem)) {
return jQuery.prop(elem, name, value);
}
var ret, hooks,
notxml = nType !== 1 || !jQuery.isXMLDoc(elem);
// Normalize the name if needed
name = notxml && jQuery.attrFix[ name ] || name;
hooks = jQuery.attrHooks[ name ];
if (!hooks) {
// Use boolHook for boolean attributes
if (rboolean.test(name) &&
(typeof value === "boolean" || value === undefined || value.toLowerCase() === name.toLowerCase())) {
hooks = boolHook;
// Use formHook for forms and if the name contains certain characters
} else if (formHook && (jQuery.nodeName(elem, "form") || rinvalidChar.test(name))) {
hooks = formHook;
}
}
if (value !== undefined) {
if (value === null) {
jQuery.removeAttr(elem, name);
return undefined;
} else if (hooks && "set" in hooks && notxml && (ret = hooks.set(elem, value, name)) !== undefined) {
return ret;
} else {
elem.setAttribute(name, "" + value);
return value;
}
} else if (hooks && "get" in hooks && notxml) {
return hooks.get(elem, name);
} else {
ret = elem.getAttribute(name);
// Non-existent attributes return null, we normalize to undefined
return ret === null ?
undefined :
ret;
}
};
})(jQuery);
यह किस त्रुटि का उत्पादन करता है? –
आप किस प्रकार के तत्वों का उपयोग कर रहे हैं? jquery 1.6 में वे विशेष रूप से बदलते हैं कि एटीआर कैसे काम करता है, अब आप गुणों को सेट करने के लिए डीआईवी टैग और टेबल जैसे कुछ एचटीएमएल तत्वों पर प्रोप का उपयोग करते हैं: http://api.jquery.com/prop/ – John
अमान्य 'इन' ऑपरेंड elem - अगर (! (elem में "getAttribute") { गोपनीय रूप से, मैंने jQuery के कुछ हिस्सों को संशोधित करने से पहले इस तकनीक का उपयोग किया है, यह केवल एटीआर फ़ंक्शन (अब तक) लगता है जो ओवरराइट स्वीकार नहीं करता है। – Steve