简体   繁体   English

将数组传递到jQuery插件中

[英]Passing Arrays into a jQuery PlugIn

I am looking at modifying a jQuery Plugin to cater for an additional requirement I need. 我正在考虑修改jQuery插件以满足我需要的其他要求。

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? 抱歉,不是编程问题,但是您可以将javascript数组传递给jQuery插件,以保留所有信息,还是丢失javascript和jQuery Plugin之间的数组内容?

Thanks. 谢谢。 TT. TT。

jQuery is written entirely in javascript. jQuery完全用javascript编写。 jQuery extensions (and indeed jQuery itself) are just normal functions. jQuery扩展(实际上是jQuery本身)只是普通功能。 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. jQuery用javascript编写,仅是使您的生活更轻松的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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