如何使用参数来完成HTA的标题颜色和背景?
类似的东西:
List.hta "ColorBG" "ColorTitle"
标题
<font color="#FFFFFF" Times New Roman" size="13"><center><B>List</b></center></font>
我的完整代码:
<html>
<head>
<title>My List</title>
<HTA:Application
Border= "thin"
Application="/md/input"
Scoll="NO"
Singleinstance="Yes"
SysMenu=NO
Icon="%Windir%\System32\wscript.exe">
ShowInTaskbar="Yes"
Caption="Yes">
<script type="text/vbscript">
Option Explicit
Window.resizeTo 373,610
Const csFSpec = "List.txt"
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Sub Window_OnLoad()
Dim objFile
If goFS.FileExists(csFSpec) Then
SET objFile = goFS.GetFile(csFSpec)
If objFile.Size > 0 Then
document.all.DataArea.value = goFS.OpenTextFile(csFSpec).ReadAll()
document.all.DataArea.value = document.all.DataArea.value
Else
document.all.DataArea.value =""
End If
Else
self.close
End If
End Sub
Sub SaveFile()
Dim objMM
Dim objFSOO
If document.all.DataArea.value = "" Then
Set objFSOO = CreateObject("Scripting.FileSystemObject")
Set objMM = objFSOO.CreateTextFile("List.txt")
self.close
Else
document.all.DataArea.value = Replace(document.all.DataArea.value, "\", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "/", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, ":", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "*", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "?", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, """", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "<", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, ">", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "|", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "&", "_")
document.all.DataArea.value = Replace(document.all.DataArea.value, "!", "_")
goFS.CreateTextFile(csFSpec).Write document.all.DataArea.value
DIM objFSO
DIM objFile
DIM STRLINE
DIM STRNEWCONTENTS
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("List.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.Readline
strLine = Trim(strLine)
If Len(strLine) > 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile("List.txt", ForWriting)
objFile.Write strNewContents
objFile.Close
document.all.DataArea.value = goFS.OpenTextFile(csFSpec).ReadAll()
document.all.DataArea.value = Replace(document.all.DataArea.value, vbcrlf,"|")
document.all.DataArea.value = left(document.all.DataArea.value,len(document.all.DataArea.value)-1)
document.all.DataArea.value = Replace(document.all.DataArea.value,"|",vbcrlf)
goFS.CreateTextFile(csFSpec).Write document.all.DataArea.value
self.close
End if
End Sub
Sub QuitEdit()
self.close
End Sub
Sub Redefine()
document.all.DataArea.value ="CD" & vbcrlf & "DISC" & vbcrlf & "MUSIC" & vbcrlf & "ALBUM"
End Sub
Sub Clean()
document.all.DataArea.value = ""
End Sub
</script>
</head>
<body style="overflow:hidden" bgColor="#000080"></body>
<caption></caption><hr></hr>
<font color="#FFFFFF" Times New Roman" size="13"><center><B>List</b></center></font>
<caption></caption><hr></hr>
<TR><td>
<input style="background-color:#F0F0F0; color: #000000; border: 2px transparent; float: left;" type="BUTTON" value="Clean" class="btn" id="btna" onclick="Clean" onmouseover="btna.style.background = '#808080'" onmouseout="btna.style.background = '#F0F0F0'">
<input style="background-color:#F0F0F0; color: #000000; border: 2px transparent; float: right;" type="BUTTON" value="Redefine" class="btn" id="btnb" onclick="Redefine" onmouseover="btnb.style.background = '#808080'" onmouseout="btnb.style.background = '#F0F0F0'">
</TR></td>
<Table border="3" style="width:100%; text-align: center" BORDERCOLOR=#F0F0F0>
<TR><td>
<form>
<textarea name="DataArea" rows="23" cols=37></textarea> </Table>
<TR><td>
<p>
<div align="right"><input style="background-color:#F0F0F0; color: #000000; border: 2px transparent" type="BUTTON" value=" OK " class="btn" id="btnc" onclick="SaveFile" onmouseover="btnc.style.background = '#808080'" onmouseout="btnc.style.background = '#F0F0F0'">
<input style="background-color:#F0F0F0; color: #000000; border: 2px transparent" type="BUTTON" value="Cancel" class="btn" id="btnd" onclick="QuitEdit" onmouseover="btnd.style.background = '#808080'" onmouseout="btnd.style.background = '#F0F0F0'">
</div>
</td></TR>
</form>
</body>
</html>
答案 0 :(得分:2)
<title>
和</title>
之间的文字无法设置样式。它用于在标题/标题栏中设置Internet Explorer的窗口标题。您输入的任何文字都将按字面处理。
Windows控制所有标题栏的外观。您可以在控制面板的“显示/个性化”小程序的“外观”或“Windows颜色”部分中(全局)配置它们。例如,“活动标题栏”控制Windows用于当前活动窗口的字体和颜色。
修改强>
我重新阅读了您的问题,听起来好像您的“标题”不是页面标题(<title>
),而是您在页面顶部附近显示的一些文字(您称之为“标题“)。
你可以将args传递给HTA,但解析它们有点棘手。 HTA只有CommandLine
属性,它返回完整的命令行,包括HTA的完整路径。为了简化操作,大多数人选择将其args括在引号中,因此命令行可能如下所示:
"c:\my folder\test.hta" "#ddd" "#f00"
在这里,我们将两个args(HTML颜色)传递给HTA。要检索它们,我们可以将CommandLine
属性拆分为引号(Chr(34)
),我们会得到以下内容:
a = Split(myhta.CommandLine, Chr(34))
a(0) = <blank>
a(1) = "c:\my folder\test.hta"
a(2) = " "
a(3) = "#ddd"
a(4) = " "
a(5) = "#f00"
a(6) = <blank>
因此,a(3)
成为您的第一个arg,a(5)
成为您的第二个arg。现在,您只需将这些值分配给HTML元素的style.backgroundColor
和style.color
属性。
以下是一个例子:
<head>
<HTA:APPLICATION
ID="htatest"
APPLICATIONNAME="HTA Test"
>
</head>
<body>
<span id="mytitle">This is a title</span>
</body>
<script language="VBScript">
Sub Window_OnLoad()
a = Split(htatest.CommandLine, Chr(34))
mytitle.style.backgroundcolor = a(3)
mytitle.style.color = a(5)
End Sub
</script>