VBScript tutorial Lesson 2 add VBscript code to the HTML page

Source: Internet
Author: User

VB tutorial> Lesson 2 add VBscript code to the HTML page
The SCRIPT element is used to add VBScript code to the HTML page.

<SCRIPT> MARK

VBScript code is written in pairs between <SCRIPT> tags. For example, the following code is a test transfer date process:

<Script language = "VBScript">
<! --
Function CanDeliver (Dt)
CanDeliver = (CDate (Dt)-Now ()> 2
End Function
-->
</SCRIPT>

The start and end parts of the Code are marked with <SCRIPT>. The LANGUAGE attribute is used to specify the Script LANGUAGE used. Because the browser can use multiple Script languages, you must specify the Script language used here. Note that the CanDeliver function is embedded in the annotation mark (<! -- And -->. This prevents the browser that cannot recognize the <SCRIPT> flag from displaying the code on the page.
Because the above example is a general function (not dependent on any form control), you can include it in the HEAD part of the page:

<HTML>
<HEAD>
<TITLE> order </TITLE>
<Script language = "VBScript">
<! --
Function CanDeliver (Dt)
CanDeliver = (CDate (Dt)-Now ()> 2
End Function
-->
</SCRIPT>
</HEAD>
<BODY>
...

The SCRIPT block can appear anywhere on the HTML page (in the BODY or HEAD part ). However, it is best to place all the general target Script code in the HEAD part so that all the Script code can be placed in a centralized manner. This ensures that all Script code is read and decoded before the BODY part calls the code.
An exception to the preceding rule is that internal code is provided in the form to respond to events of objects in the form. For example, the following example embeds Script code in the form to respond to the button clicking event in the form:

<HTML>
<HEAD>
<TITLE> test button event </TITLE>
</HEAD>
<BODY>
<Form name = "Form1">
<Input type = "Button" NAME = "Button1" VALUE = "click">
<Script for = "Button1" EVENT = "nClick" LANGUAGE = "VBScript">
The MsgBox button is clicked! "
</SCRIPT>
</FORM>
</BODY>
</HTML>

Most Script code is executed only when other code calls Sub or Function. However, you can also place the VBScript code outside the process and in the SCRIPT block. This type of code is executed only once when an HTML page is loaded. In this way, you can initialize the data or dynamically change the appearance of the page when loading the Web page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.