HTML表单输入文本框中VBScript变量如何调用CWD?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (82)

我有一个输入文本框,我想在加载时显示当前的工作目录。

<script language = "VBScript">
Dim cwd 
cwd = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Dim Master
Dim Master1
Dim folderdefault
folderdefault = cwd

Sub ChooseSaveFolder
    strStartDir = ""
    userselections.txtFile.value = PickFolder(strStartDir)
End Sub 

Function PickFolder(strStartDir)
    Dim SA, F
    Set SA = CreateObject("Shell.Application")
    Set F = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
    If (Not F Is Nothing) Then
        PickFolder = F.Items.Item.path
    End If
    Set F = Nothing
    Set SA = Nothing
End Function 

Sub CheckMaster
    Master = userselections.txtFile.value
    If userselections.txtFile.value ="" Then
        MsgBox "No folder selected." & folderdefault
    Else
        ' Alert "Default folder is now : " & vbCrLf & Master & vbCrLf & cwd
        MsgBox "Default folder selected:" & vbCrLf & folderdefault & vbCrLf & "Master=" & Master & vbCrLf & "cwd=" & cwd
    End If        
End Sub
</script>

HTML调用变量CWD并自动填充文本区域:

<form name="userselections">
    <input type="button" value = "Select Folder" onClick="ChooseSaveFolder()" />
    <input type="button" value="Submit" name="run_button"  onClick="vbscript:CheckMaster"><br>
    <input type="text" name="txtFile" class="folder" value=cwd />
</form>

输入文本的“Value”部分在文本字段中只显示字面上的“CWD”。我不确定如何调用VBScript变量CWD并将其放入文本区域。我觉得这和:

document.userselections.txtFile.value = folderdefault

如果JavaScript可以调用VBScript变量,我将如何做到这一点?

提问于
用户回答回答于

将此添加到VBScript上的任何位置:

Sub Window_onLoad
    document.getElementsByName("txtFile")[0].value = cwd
End Sub
用户回答回答于

以下工作:

<html>
<head>
<script language="vbscript">
    Option Explicit
    Dim cwd
    cwd = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
</script>
<script language="javascript">
    window.alert(cwd);
</script>
</head>
<body>
</body>
</html>

当用.hta扩展和运行时,它将显示HTA的当前文件夹。


你应该能够从VBScript中执行以下操作:

document.userselections.txtFile.value = folderdefault

但是,你必须确保表单元素已经加载。对于你来说,最简单的方法是在下面的代码中包含另一个脚本元素,body要素:

<script language="vbscript">
    document.userselections.txtFile.value = folderdefault
</script>

扫码关注云+社区

领取腾讯云代金券