简体   繁体   English

JQuery:如何通过简单的函数制作JQuery插件?

[英]JQuery: How to make a JQuery plugin from a simple function?

I have made this simple function that add placeholders to browsers that do not support them by default, like Explorer 8. 我做了一个简单的功能,即在默认情况下不支持占位符的浏览器中添加占位符,例如Explorer 8。

DEMO 演示

The question is: How can i make a plugin with that function? 问题是:如何制作具有该功能的插件? In order to remove the code from the html file and put it in a separate js file? 为了从html文件中删除代码并将其放在单独的js文件中?

Thank you! 谢谢!

Just so you know: there is already a plugin for that. 就是这样,您已经知道:已经有一个插件

JQuery UI has a nice learning center . JQuery UI有一个不错的学习中心

Basic example from learning center above: 来自上述学习中心的基本示例:

(function ( $ ) {

    var shade = "#556b2f";

    $.fn.placeholder = function() {
        // your code
        return this;
    };

}( jQuery ));

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

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