item 方法 (Visual Studio - JScript)
傳回集合物件中的目前項目。
function item() : Number
備註
item 方法會傳回 Enumerator 物件中的現有項目。 如果集合物件是空的,或目前的項目尚未定義的話,將會傳回 undefined。
範例
在下列程式碼中,使用 item 方法傳回 Drives 集合物件的成員。
function ShowDrives()
{
var s = "";
var bytesPerGB = 1024 * 1024 * 1024;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var e = new Enumerator(fso.Drives);
e.moveFirst();
while (e.atEnd() == false)
{
var drv = e.item();
s += drv.Path + " - ";
if (drv.IsReady)
{
var freeGB = drv.FreeSpace / bytesPerGB;
var totalGB = drv.TotalSize / bytesPerGB;
s += freeGB.toFixed(3) + " GB free of ";
s += totalGB.toFixed(3) + " GB";
}
else
{
s += "Not Ready";
}
s += "\n";
e.moveNext();
}
return(s);
}