简体   繁体   中英

Passing Arrays into a jQuery PlugIn

I am looking at modifying a jQuery Plugin to cater for an additional requirement I need.

Sorry, not a programming question, but can you pass an array from javascript into a jQuery plugin, that will maintain all it's information or do I lose the array content between javascript and jQuery Plugin?

Thanks. TT.

jQuery is written entirely in javascript. jQuery extensions (and indeed jQuery itself) are just normal functions. There's nothing special nor different about it, so to answer your question, yes you can pass arrays.

Here's an example plugin that has an array as an argument.

// plugin definition
$.fn.myPlugin = function(arrArg) {
    // the plugin implementation code goes here
    // do something with arrArg, which is an array
};

Then to call the plugin with an array:

$('.class').myPlugin([1, 2, 3]);

Your array should have all the same data as it had when you passed it. jQuery is written in javascript and is merely a framework to make your life easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM