VBScript 除錯物件



除錯物件是全域性物件,可以將輸出傳送到指令碼偵錯程式。這裡的偵錯程式指的是 Microsoft Script Debugger。

Debug 物件不能像其他物件一樣建立,但可以在除錯時使用。

Debug 物件支援以下方法。如果指令碼不是在除錯模式下執行,則這些方法或物件無效。Debug 物件支援的方法將在後面詳細討論。

Write

Write 方法在執行時將字串傳送到 Microsoft Script Debugger 的立即視窗。如果指令碼不是在除錯模式下執行,則 Write 方法無效。

Write Debug.Write([str1 [, str2 [, ... [, strN]]]])

示例

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         Dim counter
         counter = 42
         Debug.Write "The value of counter is " & counter
       
      </script>
   </body>
</html>

WriteLine

WriteLine 方法與 Write 方法非常相似。WriteLine 方法在執行時將字串(後跟換行符)傳送到 Microsoft Script Debugger 的立即視窗。如果指令碼不是在除錯模式下執行,則 WriteLine 方法無效。

Debug.WriteLine([str1 [, str2 [, ... [, strN]]]])

示例

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         Dim counter
         counter = 42
         Debug.WriteLine "The value of counter is " & counter
       
      </script>
   </body>
</html>

啟用除錯模式

要以除錯模式啟用指令碼,使用者需要執行以下操作:

  • 工具選單上,單擊“Internet 選項”。

  • 在“Internet 選項”對話方塊中,單擊“高階”選項卡。

  • 在“瀏覽”類別中,清除“停用指令碼除錯”複選框。

  • 單擊“確定”。

  • 退出並重新啟動 Internet Explorer。

vbscript_object_oriented.htm
廣告