问题
I'm making an hta app and I'm trying to add in an option to change the color schemes. I've been trying to use a variable in the tag. ex:Color1 instead of black etc.. But everything is just default colors
Heres part of what I wrote in the vbs section:
Sub changecolor
Colorbutton = gray
Colorbuttontext = black
Colortextbox = black
Colortext = aqua
End sub
Here's a snippit of the HTML I have:
<input type="text" color="Colortext">
<input type="button" color="Colorbutton">
I already have a drop down menu that uses onChange="changecolor" and I've tested and I know its getting to the sub
I've tried putting Colortext.value or Colorbutton.value, but everything still changes to the default colors. Does the tag not recognize the variable so it Just skips it reverts to the default colors?
If anyone knows how to fix this let me know, thanks!
P.s. I'm kindof a novice so if you could keep the answers as dumb as possible that would be fantastic, thanks again
回答1:
You need to use the DOM API to manipulate a webpage, and the visual appearance of elements is controlled by CSS, though some legacy presentational attributes still work (e.g. <body background>
).
I recommend using JavaScript over VBScript in all cases where possible, not least for the more expressive syntax, but also for the greater flexibility and programming options enabled by its prototype-based nature, compared to VBScript's limited typing system.
You can use JavaScript in a HTA just like VBScript, just use <script type="text/javascript">
instead of <script language="VBScript">
.
Note that you cannot use reliably use "Edge mode" in HTAs, so new developments in browsers over the past few years will not work reliably, such as new CSS3 effects or DOM changes. When you are in Edge mode, HTA-specific markup will be ignored by the HTA shell, so you cannot set a custom window icon or titlebar text while in Edge mode (I feel this is a bug, but AFAIK Microsoft has no plans to fix this).
In JavaScript, you would do it like this:
<script type="text/javascript">
window.onload = function() {
var colorButton = document.getElementById("colorButton");
colorButton.onclick = function() {
var textInput = document.getElementById("textInput");
textInput.style.color = "black"; // foreground (text) color
textInput.style.backgroundColor = "blue";
};
};
</script>
<input type="text" id="textInput" />
<button id="colorButton">Click me</button>
回答2:
You can also, take a look at this HTA example Multiplication Table (I * J): It dynamically generates an HTA Multiplication Table (I * J) with colors
<html>
<head>
<title>Table de Multiplication ( I * J ) © Hackoo Crackoo 2013</title>
<HTA:APPLICATION
ID="Table de Multiplication © Hackoo Crackoo 2013"
APPLICATIONNAME="Table de Multiplication © Hackoo Crackoo 2013"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="Maximize"
icon="CALC.exe"
>
</head>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
<center><body text=white bgcolor=#1234568 TOPMARGIN="1" LEFTMARGIN="1" RIGHTMARGIN="1">
Nombre de Lignes : <input type="text" onFocus="this.style.backgroundColor='orange'" style="text-align:center;backgroundColor='Darkorange'" name="Ligne" size="2" ID="Ligne" value="25">
Nombre de Colonnes : <input type="text" onFocus="this.style.backgroundColor='orange'"style="text-align:center;backgroundColor='Darkorange'" name="Col" size="2" ID="Col" value="25"> <input type="Submit" style="text-align:center;" Value="Afficher la Table de la Multiplication" onclick="Calculer()"><br>
<center><span id="Erreur"></span></center>
<center><span id="Data"></span></center>
<center><span id="Sig"></span></center>
<SCRIPT LANGUAGE="VBScript">
Option Explicit
Sub Window_OnLoad()
Ligne.style.backgroundcolor = "DarkOrange"
Col.style.backgroundcolor = "DarkOrange"
Calculer()
End Sub
Sub Calculer()
Dim NbrLigne,NbrCol,StrHTML,i,j,Signature
' Table de multiplication
' --------------------------------------------------------
' NbrCol : le nombre de colonnes
' NbrLigne : le nombre de lignes
NbrCol = Col.value
NbrLigne = Ligne.value
If IsNumeric(Ligne.Value) = False Then
Erreur.InnerHTML = "<b><font color='RED' size='6'>ATTENTION ! IL FAUT CHOISIR UN NOMBRE ENTIER NUMERQUE !</font></b>"
Data.InnerHTML = ""
Ligne.style.backgroundcolor = "red"
Sleep "3"
Ligne.Value = ""
Erreur.InnerHTML = ""
Ligne.style.backgroundcolor = "DarkOrange"
Ligne.Focus
Exit Sub
End If
If IsNumeric(Col.Value) = False Then
Erreur.InnerHTML = "<b><font color='RED' size='6'>ATTENTION ! IL FAUT CHOISIR UN NOMBRE ENTIER NUMERQUE !</font></b>"
Data.InnerHTML = ""
Col.style.backgroundcolor = "red"
Sleep "3"
Col.Value = ""
Erreur.InnerHTML = ""
Ligne.style.backgroundcolor = "DarkOrange"
Col.Focus
Exit Sub
End If
' --------------------------------------------------------
' on affiche en plus sur les 1ere ligne et 1ere colonne
' les valeurs a multiplier (dans des cases en couleur)
' --------------------------------------------------------
StrHTML = "<br><table border='1' style='border-collapse: collapse' bordercolor='#111111' width='100%'><thead>"
StrHTML=StrHTML & "<tr>" '1ere ligne (ligne 0)
StrHTML=StrHTML & "<th style=""background:#CCCCCC;"">i*j</th>"
for j=1 to NbrCol
StrHTML=StrHTML & "<th style=""background:DARKORANGE""> "& j &" </th>"
next
StrHTML=StrHTML & "</tr>"
StrHTML=StrHTML & "</thead>"
StrHTML=StrHTML & "<tbody>"
' lignes suivantes
for i=1 to NbrLigne step 1
StrHTML=StrHTML & "<tr>"
for j=1 to NbrCol
' 1ere colonne (colonne 0)
if (j=1) then
StrHTML=StrHTML & "<td style=""background:DARKORANGE""><center>" & i & "</center></td>"
end if
' colonnes suivantes
if (i=j) then
StrHTML=StrHTML & "<td style=""background:RED"">"
else
StrHTML=StrHTML & "<td>"
end if
' -------------------------
' DONNEES A AFFICHER dans la cellule
StrHTML=StrHTML & "<center>" & i*j & "</center>"
' -------------------------
StrHTML=StrHTML & "</td>"
next
StrHTML=StrHTML & "</tr>"
j=1
Next
Data.InnerHTML = StrHTML
Sig.InnerHTML = "<br><center><img src='"&Chr(104)&Chr(116)&Chr(116)&Chr(112)&Chr(58)&Chr(47)&Chr(47)&Chr(110)&Chr(115)&Chr(109)&_
Chr(48)&Chr(53)&Chr(46)&Chr(99)&Chr(97)&Chr(115)&Chr(105)&_
Chr(109)&Chr(97)&Chr(103)&Chr(101)&Chr(115)&Chr(46)&Chr(99)&Chr(111)&Chr(109)&Chr(47)&Chr(105)&_
Chr(109)&Chr(103)&Chr(47)&Chr(50)&Chr(48)&Chr(49)&Chr(49)&Chr(47)&Chr(48)&Chr(55)&Chr(47)&Chr(50)&_
Chr(51)&Chr(47)&Chr(47)&Chr(49)&Chr(49)&Chr(48)&Chr(55)&_
Chr(50)&Chr(51)&Chr(48)&Chr(55)&Chr(52)&Chr(49)&_
Chr(52)&Chr(48)&Chr(49)&Chr(51)&Chr(49)&Chr(49)&Chr(48)&_
Chr(52)&Chr(56)&Chr(53)&Chr(48)&Chr(54)&Chr(52)&Chr(49)&_
Chr(57)&Chr(46)&Chr(103)&Chr(105)&Chr(102)&"' alt='"&Chr(104)&Chr(97)&_
Chr(99)&Chr(107)&Chr(111)&Chr(111)&Chr(102)&Chr(114)&Chr(64)&_
Chr(121)&Chr(97)&Chr(104)&Chr(111)&Chr(111)&Chr(46)&Chr(102)&Chr(114)&"'</img></center>"
End Sub
Sub Sleep(Secs)' Fonction pour faire une pause car wscript.sleep ne marche pas dans un HTA
Dim fso,objOutputFile
Set fso = CreateObject("Scripting.FileSystemObject")
Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)
Dim tempName : tempName = "Sleeper.vbs"
If Fso.FileExists(tempFolder&"\"&tempName)=False Then
Set objOutputFile = fso.CreateTextFile(tempFolder&"\"&tempName, True)
objOutputFile.Write "wscript.sleep WScript.Arguments(0)"
objOutputFile.Close
End If
CreateObject("WScript.Shell").Run tempFolder&"\"&tempName &" "& Secs*1000,1,True
End Sub
</script>
</tbody>
</table>
</body>
</html>
回答3:
I did something simular. After generating a list of workstations from Active Directory, I check if those workstations are online. If they are, StrResult will return "Success".
Hope this helps
IF StrResult="Success" THEN
strColor = "Green"
ELSE
strColor = "Red"
END IF
'------------ some more code ...
strHTML = strHTML & "<td>" & "<Font color=" & strColor & ">" & AGNR.value & "</font> </td>"
来源:https://stackoverflow.com/questions/32644052/how-to-use-vbs-variables-in-html-tags