2011-04-09 2 views
0

내가 그렇게 보이는 외부 jQuery 코드가 있습니다JQuery와 변수

jQuery(function($){ 

    $.supersized({ 
     navigation    : 1, //Slideshow controls on/off 
     thumbnail_navigation : 1, //Thumbnail navigation 
     slide_counter   : 1, //Display slide numbers 
     slide_captions   : 1, //Slide caption (Pull from "title" in slides array) 
     slides     : [ 
         {image : 'some/path', title : 'title'}, 
         {image : 'some/path', title : 'title'}, 
         {image : 'some/path', title : 'title'} 

     ] //Slide Images to be specified on page 
    }); 
}); 

내가 $ 같은 몇 가지 변수에 의해 slide_urls을 '슬라이드'OPTIO를 교체하고 개별 HTML 페이지에 이미지 경로를 선언 할 수 있습니까?

답변

2

변수 $ slide_urls가 supersized() 함수 내에서 볼 수있는 어딘가에 선언되어 있고 객체 배열 인 한, 페이지의 다른 위치에 쉽게 설정하고 함수에서 참조 할 수 있습니다.

$(window).ready(function(){ 
    $slide_urls = [ /* specific slides for the page */ ]; 
    // ... other code 
    $.supersized({ 
    // other options 
    slides: $slide_urls 
    } 
} 
1

slide_urls을 전역 변수로 선언 할 수 있습니다.

// in your "external" code: 

function setup(urls) { 
    $.supersized({ 
     //... 
     slides: urls 
    }); 
} 

// in the pages 

$(function() { 
    setup([/*...urls here...*/]); 
}); 
:

그러나, IMO는 자신의 기능에이 코드를 삽입하고 올바른 데이터를 전달 페이지에서 호출하는 것이 좋습니다