- 1、本文档共12页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
用jquery写插件(Write a plug-in with jquery)
用jquery写插件(Write a plug-in with jquery)
1, plug-in class level
1.1 add a new global function
(jQuery.foo = function) {
Alert (This is a test.Just do you test01);
}
1.2 increase the number of global functions
(jQuery.foo = function) {
Alert (This is a test. This is only a test.);
};
JQuery.bar = function (param) {
Alert (This function takes a parameter, which is + param + .);
};
JQuery.alertParm (param) {
Alert (This function takes a parameter, which is +param+);
}
The call and a function of the same: (jQuery.foo); jQuery.bar ($.foo); or ($.bar); (bar);
1.3 using jQuery.extend (object);
JQuery.extent ({
{(foo:function)
Alert (This is a test----use jQuery.extend (Object) );
}
Bar:function (param) {
Alert (This function takes a parameter, which is +param+);
}
});
1.4 use namespace
Although in the jQuery namespace, we prohibit the use of a large number of javaScript function and variable names. But still can not avoid
Free some function or variable name in other conflicts jQuery plug-in, so we used some methods package to another custom namespace.
JQuery.myPlugin = {
{(foo:function)
Alert (This is a test function );
}
Bar:function (param) {
Alert (This funciotn takes a param, which is +param+);
}
};
The namespace function is still the global functions, the method call is used:
($.myPlugin.foo);
$.myPlugin.bar (param);
2, the object level plug-in development
The plug-in development object level need two forms as follows:
Form 1:
(function ($) {
$.fn.extend ({
PluginName:function (OPT, callback) {
//our plugin implemention code goes here
}
})
}) (jQuery)
Form 2:
(function ($) {
($.fn.pluginName = function) {
//our plugin implemention code goes here
};
});
2.1 in the JQuery namespace to declare a name
($.fn.hilight = function) {
Plugin implementation code goes here. / / Our
};
Our plugin is invoked by this:
$(#myDiv).Hilight ();
The 2.2 options parameters to control the behavior of the plug-in
Lets add function specifies the foreground and background colors for our plugin.
您可能关注的文档
- 焊接资料(Welding materials).doc
- 焊条温度(Electrode temperature).doc
- 焦作好吃的地方(Nice place to eat in Jiaozuo).doc
- 焊缝要求(Weld).doc
- 焦炭指标(Coke index).doc
- 焦糖玛奇朵(Caramel Macchiato).doc
- 焊接标准(Welding standard).doc
- 煎煮时间对生大黄中五种游离蒽醌的影响(Effect of decocting time on five kinds of free anthraquinone in Rhubarb).doc
- 煤炭企业发展环保产业的思考(Thoughts on the development of environmental protection industry in Coal Enterprises).doc
- 煤矿领导带班下井及安全监督检查规定——无广告(Leadership class to go down and mine safety supervision and inspection requirements, no ads).doc
文档评论(0)