0

This is probably a duplicate question, but I can't find it.

I understand " How to add a function to jQuery? " - with the activation of that function being something like:

jQueury(selector).myFunction();

But jQuery also has some "core" functions that can be activated like:

jQuery.ajax(options);

If I want to add a function to jQuery that does not act on an element, like a logging function, how would I be able to achieve adding it to the "core" so that it can be activated like:

jQuery.log('message');
4

2 に答える 2

3

を使用し$.extend( { functionName: function() { ... } } );ます。

またはもっと簡単に: $.functionName = function() { ... };.

于 2012-07-23T04:37:35.590 に答える
1

So just define it:

$.log = function(str) { alert(str); };

jQuery.log('foo bar');

http://jsfiddle.net/zerkms/4TAcv/

于 2012-07-23T04:35:09.713 に答える