访问javascript变量

时间:2010-11-10 11:46:41

标签: asp.net

我想将照片数组分配给imagearray,但以下脚本无效。 我无法在新的fadeSlideShow().how中访问变量a,i,cnlink等,以便在函数外部访问它并将其分配给imagearray

 <script type="text/javascript">
         var i; var a; var cnLink; var cn;var cnSplit;
         var photos = new Array();
         var photoslink = new Array();
         function x() {
            a = document.getElementById('HiddenField4').value;
            cnLink = document.getElementById('hdnLink').value;
              cn = document.getElementById('HiddenField3').value;
          cnSplit = cnLink.split(';');
             while (i < cn) {
                 photoslink[i] = cnSplit[i];
                 photos[i] = b[i];
                 i++;
             }
         }

         var mygallery2 = new fadeSlideShow({
             wrapperid: "fadeshow2",
             dimensions: [568, 313],
             imagearray: [
             photos
         //<--array of images!
    ],
             displaymode: { type: 'auto', pause: 2500, cycles: 0, wraparound: false },
             persist: false, //remember last viewed slide and recall within same session?
             fadeduration: 500, //transition duration (milliseconds)
             descreveal: "always",
             togglerid: "fadeshow2toggler"
         })


</script>

1 个答案:

答案 0 :(得分:0)

<script type="text/javascript">
         var i; var a; var cnLink; var cn;var cnSplit;
         var photos = new Array();
         var photoslink = new Array();
         function x() {
            a = document.getElementById('HiddenField4').value;
            cnLink = document.getElementById('hdnLink').value;
              cn = document.getElementById('HiddenField3').value;
          cnSplit = cnLink.split(';');
             while (i < cn) {
                 photoslink[i] = cnSplit[i];
                 photos[i] = b[i];
                 i++;
             }
         }

         x(); // try executing your function as well.

         var mygallery2 = new fadeSlideShow({
             wrapperid: "fadeshow2",
             dimensions: [568, 313],
             imagearray: [
             photos
         //<--array of images!
    ],
             displaymode: { type: 'auto', pause: 2500, cycles: 0, wraparound: false },
             persist: false, //remember last viewed slide and recall within same session?
             fadeduration: 500, //transition duration (milliseconds)
             descreveal: "always",
             togglerid: "fadeshow2toggler"
         })


</script>

或者你可以放弃定义这个功能。

<script type="text/javascript">
var i;
var a;
var cnLink;
var cn;
var cnSplit;
var photos = new Array();
var photoslink = new Array();

a = document.getElementById('HiddenField4').value;
cnLink = document.getElementById('hdnLink').value;
cn = document.getElementById('HiddenField3').value;
cnSplit = cnLink.split(';');
while (i < cn) {
    photoslink[i] = cnSplit[i];
    photos[i] = b[i];
    i++;
}

var mygallery2 = new fadeSlideShow({
    wrapperid: "fadeshow2",
    dimensions: [568, 313],
    imagearray: [
        photos
        //<--array of images!],
    displaymode: {
        type: 'auto',
        pause: 2500,
        cycles: 0,
        wraparound: false
    },
    persist: false,
    //remember last viewed slide and recall within same session?
    fadeduration: 500,
    //transition duration (milliseconds)
    descreveal: "always",
    togglerid: "fadeshow2toggler"
})
</script>