Writing jQuery plugins is easy. Everyone who has the basic jQuery knowledge is capable to write jQuery plugins. It is just as simply as appending a function to jQuery.fn object.
However, if you only have little knowledge about jQuery Plugin, you can even try to modify the content from a jQuery Plugin Template.
By the way, paying attention to the following designing rules should help improving the quality of a jQuery Plugin:
Avoid using global variables. jQuery plugins should be worked properly in all kinds of circumstances and global variables should be avoided in order to prevent conflict of usages of variables with same name.- Uses the "jQuery" variable instead of "$" to avoid conflict of libraries. There may be conflict of libraries when some libraries are using "$", too.
- You plugin should return the same DOM list as they are passed from jQuery selector engine if possible. To return the same DOM list can ensure the chainability in using the plugin.
Happy Programming,
Cloudgen Wong
0 意見:
張貼意見