jquery is a popular JS framework, custom JS method, encapsulated into jquery, call up is also very convenient, how to write jquery extension method that, the Web read a part of the code, in fact, quite simple:
Way One:
(jquery.fn.setapdiv=function () {//Apdiv Floating Layer display position centering control varwheight=$ (window). Height (); varWwidth=$ (window). width (); varapheight=wheight-$ ("#apDiv"). Height (); varapwidth=wwidth-$ ("#apDiv"). width (); $("#apDiv"). CSS ("Top", apheight/2); $("#apDiv"). CSS (" Left", apwidth/2); }) or: (function ($) {$.fn.extend ({//pop-up window masking layershowloaddialog:function () {//Apdiv Floating Layer display position centering control varwheight=$ (window). Height (); varWwidth=$ (window). width (); varapheight=wheight-$ ("#apDiv"). Height (); varapwidth=wwidth-$ ("#apDiv"). width (); $("#apDiv"). CSS ("Top", apheight/2); $("#apDiv"). CSS (" Left", apwidth/2); })}) (JQuery)
Calling code:
$ ("#apDiv"). Setapdiv ();
Way two:
Jquery.extend ({//Set Apdivsetapdiv:function () {//Apdiv Floating Layer display position centering control varwheight=$ (window). Height (); varWwidth=$ (window). width (); varapheight=wheight-$ ("#apDiv"). Height (); varapwidth=wwidth-$ ("#apDiv"). width (); $("#apDiv"). CSS ("Top", apheight/2); $("#apDiv"). CSS (" Left", apwidth/2); } }); Or: (function ($) {$.extend ({//pop-up window masking layershowloaddialog:function () {//Set Apdivsetapdiv:function () {//Apdiv Floating Layer display position centering control varwheight=$ (window). Height (); varWwidth=$ (window). width (); varapheight=wheight-$ ("#apDiv"). Height (); varapwidth=wwidth-$ ("#apDiv"). width (); $("#apDiv"). CSS ("Top", apheight/2); $("#apDiv"). CSS (" Left", apwidth/2); })}) (JQuery)
Calling code:
$.setapdiv ();
Third, Expansion:
In jquery, Ajax commits, in the form of forms, we take the method of removing the input value, and then composing the JSON or other way to commit, if repeated with $ ("#vid"). Val (), this way of processing, looks very cumbersome, can not be used to send a form with other that, After reviewing the data, we found a map method to solve the problem, the code is pasted as follows:
$.ajax ({varstr_data=$ ("#dlg_form Input"). Map (function () {return($( This). attr ("name")+'='+$( This). Val ());}).Get(). Join ("&") ; Type:"POST", URL:"some.php", Data:str_data, Success:function (msg) {alert ("Data Saved:"+msg); }});
Refer to Good blog post address: http://www.cnblogs.com/nangong/archive/2013/07/23/3208302.html
jquery Custom Extension methods