jQuery 开发插件

来源:互联网 发布:如何看待知乎live 编辑:程序博客网 时间:2024/06/10 02:58

$.extend

$.fn.extend

实例1

$.extend({

min:function(a,b){ return  a<b? a:b},

max:function(a,b){return a>b? a:b}

})

$.min(1,3);//1

$.max(2,4);//4



$.fn.extend

是对jQuery的prototype进行扩展,添加成员函数,jQuery类的实例可以使用这个函数


(function($){
$.fn.extend({
 writeparameter:function (url) {
  var id="4f1cfcc7-de5d-4739-a8f6-be473a19f10d";
//     $.post(basePath+url,
//    {id:id},
//    function(data,status){
//        alert("Data: " + data + "\nStatus: " + status);
//
//    },
//    "json");
     $.ajax({
      type:"POST",
      url:basePath+url,
      data:{
       id:id
      },
      dataType: "json",
            success: function(data){
             //alert("cg");
             $.each(data, function(key, value){
              if(key=="select"){
               
              }else{
               document.getElementById(key).value=value;
              }
             });
             
           },
           error: function(XMLHttpRequest, textStatus, errorThrown) {
    alert("xx");
   }
     });
    }
});
})(jQuery)

使用

$.("#control").writeparameter(url);



0 0
原创粉丝点击