vb.net 教程 12-3 HtmlElement类 3

来源:互联网 发布:免费外汇交易软件 编辑:程序博客网 时间:2024/06/06 03:05
上一节我们已经学习了GetAttribute方法,本节来看看GetAttribute()和SetAttribute()方法更高级的用途:比如自动填表。。。

为了更好的说明使用我在我的网站上建立了2个简单的网页,网址为:http://www.qqrec.com/vblessons/vbnet20-2-1.htm
具体代码如下:
1、vbnet20-2-1.htm
<html><head><title>这是配合vb.net教程的网页</title><script language="javascript">function check(){if(sampleform.studentname.value==""){alert("姓名没有填写");return false;}if(sampleform.studentage.value.length>2){alert("年龄长度超过2位");return false;}sampleform.submit();}</script></head><body><form name="sampleform" id="sampleform" action="vbnet20-2-1.asp" method="post" target="_self">输入学生姓名:<input type="text" name="studentname" id="studentname" maxlength="6"> <br/>输入学生年龄:<input type="test" name="studentage" id="studentage" maxlength="6"> <br/><input type="button" name="submit1" id="submit1" value="提交1" onclick="check()"><input type="button" name="submit2" id="submit2" value="提交2" onclick="check()" disabled="disabled"></form></body></html>
说明一下:
一是简单的判断是否填写了姓名,如果姓名没有填写,那么不会提交;
二是判断年龄文本框内的长度是否超过3,如果超过,那么不会提交,
以上两个判断本节暂时没有用,以后还会用到。
在网页中显示如下:
2、vbnet20-2-1.asp:
<html><head><title>这是配合vb.net教程的网页</title></head><body><%dim studentnamedim studentagestudentname=request.form("studentname")studentage=request.form("studentage")%>学生姓名:<%=studentname%> <br/>学生年龄:<%=studentage%> <br/></body></html>
这个asp页面只是简单的接收提交来的数据并显示出来:



由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看vb.net 教程 目录


原创粉丝点击