需要 VBScript 对象

VBScript object required

Option Explicit 
Dim output, ProxyEnable, ProxyServer, wshShell, doc

Sub Window_onLoad
    loadProxySettings()
End Sub 

Set wshShell = CreateObject("WScript.Shell")
ProxyEnable = wshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
ProxyServer = wshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer")

Function loadProxySettings()
    If ProxyEnable = 1 Then
        proxyStatus.className = "enabled"
        proxyStatus.innerHTML = "Proxy aktiv"

        toggleProxyButton.value = "Proxy deaktivieren"

        proxyServer.value = ProxyServer
    Else
        proxyStatus.className = "disabled"
        proxyStatus.innerHTML = "Proxy deaktiviert"

        toggleProxyButton.value = "Proxy aktivieren"

        proxyServer.value = ProxyServer
    End If 
End Function

只是找不到导致我出现错误的问题:

Object required "ProxyStatus"

(是的,我有一个 span 元素,其中 idproxyStatus

在 HTA 中,您可以像变量一样使用 ID 元素的 ID,即如果您有这样的元素:

<p>foo <span id="proxyStatus">something</span> bar</p>

您应该可以像这样在您的代码中使用它,而无需先做任何事情:

MsgBox proxyStatus.innerText

返回this code

Set ProxyStatus = document.getElementById("proxyStatus")
Set ToggleProxyButton = document.getElementById("toggleProxy")
Set ProxyServerInput = document.getElementById("proxyServer")

只要 HTML 的格式正确,这里唯一的错误就是在引用 DOM 中的现有对象时使用了 Set。尝试像这样从这些行中删除 Set

ProxyStatus = document.getElementById("proxyStatus")
ToggleProxyButton = document.getElementById("toggleProxy")
ProxyServerInput = document.getElementById("proxyServer")