2016-07-05 4 views
0

가변 요소에 사용하기 위해 코드와 같은 플러그인을 만들려고하지만 장소에 갇혀 있습니다. 나는 성공적으로 내가 플러그인을 호출하고 잘 작동하지만 난 변경하는 방법에 붙어 때 색상을 변경 $ .extend을 사용한 위의 첫 번째 코드에서 현재 코드

(function($){ 
 
       $.fn.dataTable = function(options){ 
 
        var settings = $.extend({ 
 
         color:"red" 
 
        }, options); 
 
        return this.css({ 
 
         color:settings.color 
 
        }); 
 
       } 
 
      }(jQuery)); 
 
      
 
      $('p').dataTable({ 
 
       color:"blue" 
 
      });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<p>hello</p>

참조 변수의 값은 플러그인을 호출하는 동안.

var settings = $.extend({ 
    showInterval: 10, 
    color:"red" 
}, options);` 

$.extend 소요 : 나는 당신이 원하는 생각 변수 showInterval

답변

-1

의 값을 변경해야

는 뭔가이 시도하지만이

(function($){ 
    $.fn.dataTable = function(options){ 
     var settings = $.extend({ 
      var showInterval = 10, 
      color:"red" 
     }, options); 
     return this.css({ 
      color:settings.color 
     }); 
    } 
}(jQuery)); 

$('p').dataTable({ 
    color:"blue", 
    showInterval :20 
}); 

작동하지 않습니다 두 개체를 병합합니다. 첫 번째 값의 모든 값은 사용 가능한 경우 두 번째 값의 값으로 덮어 쓰게됩니다.

관련 문제