国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

vbscript起步——與窗體的交互,函數的調用

2024-07-21 02:15:31
字體:
來源:轉載
供稿:網友
 

首先我們看這樣一段代碼:
<html>
<head><title>一個簡單首頁</title>
<script language="vbscript">
<!--
sub button1_onclick
msgbox "歡迎光臨"
end sub
-->
</script>
</head>
<body>
<h3>一個簡單首頁</h3><hr>
<form><input name="button1" type="button" value="單擊此處"></form>
</body>
</html>
這實現的是 當點擊按鈕時,彈出消息框,顯示 歡迎光臨
其中
sub 定義一個過程,過程名包含兩部分:
button1 為按鈕名(從<input> 標記中的 name 屬性獲取)
onclick 是事件名,即button1的onclick事件其中兩部分用(_)連接
合起來實現的是,單擊按鈕,internet explorer 查找并運行相應的事件過程,即 button1_onclick

<input name="button1" type="button"
value="單擊此處" onclick='msgbox "歡迎光臨"'>
函數調用包含在單引號中,msgbox 函數的字符串包含在雙引號中。只要用冒號 (:) 分隔語句,就可以使

用多條語句。

<script language="vbscript" event="onclick" for="button1">
<!--
msgbox "歡迎光臨"
-->
</script>
這種方法在<script> 標記指定了事件和控件,所以不需要再用 sub 和 end sub 語句

進一步實現簡單驗證
<html>
<head><title>簡單驗證</title>
<script language="vbscript">
<!--
sub button1_onclick
dim theform
set theform = document.validform
if isnumeric(theform.text1.value) then
if theform.text1.value < 1 or theform.text1.value > 10 then
msgbox "請輸入一個 1 到 10 之間的數字。"
else
msgbox "謝謝。"
end if
else
msgbox "請輸入一個數字。"
end if
end sub
-->
</script>
</head>
<body>
<h3>簡單驗證</h3><hr>
<form name="validform">
請輸入一個 1 到 10 之間的數字:
<input name="text1" type="text" size="2">
<input name="button1" type="button" value="提交">
</form>
</body>
</html>
這個文本框與 vbscript 頁面的簡單樣例中文本框的 value 屬性被用于檢查輸入值。要使用文本框的

value 屬性,代碼必須引用文本框的名稱。

每次引用文本框時都應寫出全稱,即 document.validform.text1。但是,當多次引用窗體控件時,可以

按照以下步驟操作:首先聲明一個變量,然后使用 set 語句將窗體 document.validform(form的id)

賦給變量 theform,這樣就能使用 theform.text1 引用文本框。常規的賦值語句(例如 dim)在這里無

效,必須使用 set 來保持對對象的引用。

進一步實現 驗證后將數據傳遞回服務器

<html>
<head><title>簡單驗證</title>
<<script language="vbscript">
<!--
sub button1_onclick
dim theform
set theform = document.validform
if isnumeric(theform.text1.value) then
if theform.text1.value < 1 or theform.text1.value > 10 then
msgbox "請輸入一個 1 到 10 之間的數字。"
else
msgbox "謝謝。"
theform.submit
end if
else
msgbox "請輸入一個數字。"
end if
end sub
-->
</script>
</head>
<body>
<h3>簡單驗證</h3><hr>
<form name="validform" action="要提交到的頁">
請輸入一個 1 到 10 之間的數字:
<input name="text1" type="text" size="2">
<input name="button1" type="button" value="提交">
</form>
</body>
</html>
sub中 theform.submit 一句指出將form的內容上傳到服務器端
有以下幾點需要注意,我在測試的時候如果將name="button1" 改為name="submit"程序出錯,原因可能是

因為submit是一個保留字
同樣,如果type="button" 改為type="submit"那么不管驗證結果如何,數據都將上傳到服務器端。


注冊會員,創建你的web開發資料庫,
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 古交市| 新乡县| 佳木斯市| 长治县| 思南县| 北辰区| 九江县| 依安县| 固始县| 沐川县| 龙山县| 浦东新区| 仪征市| 泰州市| 饶河县| 黄梅县| 五华县| 沁阳市| 巢湖市| 泰州市| 武城县| 安新县| 顺义区| 永兴县| 加查县| 兴隆县| 长岭县| 锡林郭勒盟| 略阳县| 册亨县| 公安县| 黑河市| 中方县| 台州市| 休宁县| 阿鲁科尔沁旗| 扎鲁特旗| 望江县| 阳泉市| 湛江市| 溧阳市|