且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在html标签中使用vbs变量

更新时间:2023-11-25 09:00:10

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>