Share via


moveFirst 方法

更新:2007 年 11 月

將目前的項目重設為 Enumerator 物件中的第一項。

 function moveFirst()

備註

如果集合物件中沒有任何項目的話,目前的項目會設成 undefined。

範例

在以下範例中,使用 moveFirst 方法來從清單開始處評估 Drives 集合物件的成員:

function ShowFirstAvailableDrive(){
   var fso, s, e, x;                //Declare variables.
   fso = new ActiveXObject("Scripting.FileSystemObject");
   e = new Enumerator(fso.Drives);  //Create Enumerator object.
   e.moveFirst();                   //Move to first drive.
   s = "";                          //Initialize s.
   do 
   {
      x = e.item();                 //Test for existence of drive.
      if (x.IsReady)                //See if it's ready.
      {
         s = x.DriveLetter + ":";   //Assign 1<SUP>st</SUP> drive letter to s.
         break;
      }
      else
         if (e.atEnd())             //See if at the end of the collection.
         {
            s = "No drives are available";
            break;
         }
      e.moveNext();                 //Move to the next drive.
   }
   while (!e.atEnd());              //Do while not at collection end.
   return(s);                       //Return list of available drives.
}

需求

3 版

套用至:

Enumerator 物件

請參閱

參考

atEnd 方法

item 方法 (JScript)

moveNext 方法