⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbs9.htm

📁 VBScript 是一种脚本语言
💻 HTM
字号:
<HTML>
<HEAD>
<TITLE>Adding VBScript Code to an HTML Page</TITLE> 
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="PRODUCT" CONTENT="Visual Basic Scripting Edition">
<META NAME="TECHNOLOGY" CONTENT="SCRIPTING">
<META NAME="CATEGORY" CONTENT="Tutorial">

<META NAME="Description" CONTENT="Adding VBScript Code to an HTML Page">
</HEAD>
<BODY BGCOLOR=FFFFFF LINK=#0033CC>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR VALIGN=TOP><TD WIDTH=360>
<FONT SIZE=1 COLOR=#660033>Microsoft&#174; Visual Basic&#174; Scripting Edition</FONT><BR>
<FONT SIZE=5 COLOR=#660033><B>Adding VBScript Code to an HTML Page</B></FONT>

</TD>
<TD ALIGN=RIGHT>
<FONT SIZE=2>&nbsp;<A HREF="vbstutor.htm">VBScript&nbsp;Tutorial</A>&nbsp;<BR>&nbsp;<A HREF="vbs17.htm">Previous</A>&nbsp;|&nbsp;<A HREF="vbs6.htm">Next</A>&nbsp;<P></FONT>


</TD></TR>
</TABLE> 
&nbsp;<BR>

<HR NOSHADE SIZE=1>
<BLOCKQUOTE>You can use the SCRIPT element to add VBScript code to an HTML page.</BLOCKQUOTE>
<H5>The &lt;SCRIPT&gt; Tag</H5>
<BLOCKQUOTE>
VBScript code is written within paired &lt;SCRIPT&gt; tags. For example, a procedure to test a delivery date might appear as follows:
<BLOCKQUOTE><PRE><FONT FACE="Courier New" SIZE=3>
&lt;SCRIPT LANGUAGE="VBScript"&gt; 
&lt;!--
   Function CanDeliver(Dt)
      CanDeliver = (CDate(Dt) - Now()) &gt; 2
   End Function
--&gt;
&lt;/SCRIPT&gt;
</FONT></PRE>
</BLOCKQUOTE>

Beginning and ending &lt;SCRIPT&gt; tags surround the code. The LANGUAGE attribute indicates the scripting language. You must specify the language because browsers can use other scripting languages. Notice that the <FONT FACE="Courier New" SIZE=2>CanDeliver</FONT> function is embedded in comment tags (&lt;!-- and --&gt;). This prevents browsers that don't understand the &lt;SCRIPT&gt; tag from displaying the code.<P>
Since the example is a general function&#151;it isn't tied to any particular form control&#151;you can include it in the HEAD section of the page:
<BLOCKQUOTE><PRE><FONT FACE="Courier New" SIZE=3>
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Place Your Order&lt;/TITLE&gt;
&lt;SCRIPT LANGUAGE="VBScript"&gt;
&lt;!--
   Function CanDeliver(Dt)
      CanDeliver = (CDate(Dt) - Now()) &gt; 2
   End Function
--&gt;
&lt;/SCRIPT&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
...
</FONT></PRE>
</BLOCKQUOTE>

You can use SCRIPT blocks anywhere in an HTML page. You can put them in both the BODY and HEAD sections. However, you'll probably want to put all general-purpose scripting code in the HEAD section in order to keep all the code together. Keeping your code in the HEAD section ensures that all code is read and decoded before it's needed by any calls from within the BODY section.<p>

One notable exception to this rule is that you may want to provide inline scripting code within forms to respond to the events of objects in your form. For example, you can embed scripting code to respond to a button click in a form:
<BLOCKQUOTE><PRE><FONT FACE="Courier New" SIZE=3>
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Test Button Events&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;FORM NAME="Form1"&gt;
   &lt;INPUT TYPE="Button" NAME="Button1" VALUE="Click"&gt;
   &lt;SCRIPT FOR="Button1" EVENT="onClick" LANGUAGE="VBScript"&gt;
      MsgBox "Button Pressed!"
   &lt;/SCRIPT&gt;
&lt;/FORM&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</FONT></PRE>
</BLOCKQUOTE>
 
Most of your code will appear in either <b>Sub</b> or <b>Function</b> procedures and will be called only when code you have written causes it to execute. However, you can write VBScript code outside procedures, but still within a SCRIPT block. This code is executed only once, when the HTML page loads. This allows you to initialize data or dynamically change the look of your Web page when it loads.

</BLOCKQUOTE>


<hr noshade size=1>
<p align=center><em><a href="../../common/colegal.htm">&copy; 1997 by Microsoft Corporation. All rights reserved.</a></em></p> 
</FONT>
</BODY>
</HTML>







































⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -