'源代码
<html>
<HEAD>
<base href="http://127.0.0.1/rlzy/loginPwd.jsp">
<link href="/skin/seablue/style/skin.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="config/javascript.js" >
</script>
<script language="JavaScript" type="text/JavaScript">
function checkKeydown(cell,event){
if(event.keyCode!=13)
return;
if(cell.name=="reservedProp(userId)"){
document.forms[0].elements["reservedProp(password)"].focus();
document.forms[0].elements["reservedProp(password)"].select();
}else if(cell.name=="reservedProp(password)"){
f_submit();
}
} function f_submit(){
var userId=document.forms[0].elements["reservedProp(userId)"].value;
if(userId==""){
alert("请输入帐号");
document.forms[0].elements["reservedProp(userId)"].focus();
document.forms[0].elements["reservedProp(userId)"].select();
return false;
}
var password=document.forms[0].elements["reservedProp(password)"].value;
if(password==""){
alert("请输入密码");
document.forms[0].elements["reservedProp(password)"].focus();
document.forms[0].elements["reservedProp(password)"].select();
return false;
}
SetCookieTime("userId",userId,10*365);
SetCookieTime("password",password,10*365);
document.forms[0].submit();
}
</script>
<TITLE>**管理系统
</TITLE></HEAD><BODY bgColor=#3B67B1 leftMargin=0 topMargin=0>
<form name="clientDataSetForm" method="post" action="/rlzy/loginBase.do">
<table border="0" width="100%" height="100%" background="images/back.jpg" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td>
<table border="0" background="images/bg.jpg" width="800" height="560" align="center" cellpadding="0" cellspacing="0">
<tr><td height="363"> </td></tr>
<tr><td><table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr><td width="610"> </td>
<td><table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr height="10" ><td>
<input type="text" name="reservedProp(userId)" value="" onkeydown="checkKeydown(this,event)" style="cursor:text;height:20;width:120" class="free_input">
</td></tr>
<tr height="15" ><td></td></tr>
<tr height="10" ><td >
<input type="password" name="reservedProp(password)" value="" onkeydown="checkKeydown(this,event)" style="cursor: text;height=20;width=120" class="free_input">
</td></tr>
<tr height="26"><td >
<table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr><td width="33"> </td><td width="45" style="cursor:hand" onClick="f_submit()" alt="登陆按钮"> </td><td> </td>
</tr>
</table>
</td></tr>
</table>
</td></tr>
<tr><td height="103" colspan="2" >
<table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr><td width="500"> </td><td valign="top">
</td></tr>
</table>
</td></tr>
</table>
</td></tr>
</table>
</td></tr>
</table></html>
Option ExplicitPrivate Sub Form_Load()
WebBrowser1.Navigate "http://127.0.0.1/rlzy/loginPwd.jsp"
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim vDoc, vTag
Dim i As Long
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.Length - 1
If UCase(vDoc.All(i).tagName) = "INPUT" Then
Set vTag = vDoc.All(i)
If vTag.Type = "text" Then
Select Case vTag.Name
Case "reservedProp(userId)"
vTag.Value = "123" '填写用户名
End Select
End If
If vTag.Type = "password" Then
Select Case vTag.Name
Case "reservedProp(password)"
vTag.Value = "2" '填写密码
End Select
End If
If vTag.Type = "submit" And vTag.Value = "登录" Then '登陆按钮
vTag.Click
End If
End If
Debug.Print UCase(vDoc.All(i).tagName)
Next i
End Sub问题:用户名和密码能自动填充,但因登陆按钮不是个input对象,如何提交?
<html>
<HEAD>
<base href="http://127.0.0.1/rlzy/loginPwd.jsp">
<link href="/skin/seablue/style/skin.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="config/javascript.js" >
</script>
<script language="JavaScript" type="text/JavaScript">
function checkKeydown(cell,event){
if(event.keyCode!=13)
return;
if(cell.name=="reservedProp(userId)"){
document.forms[0].elements["reservedProp(password)"].focus();
document.forms[0].elements["reservedProp(password)"].select();
}else if(cell.name=="reservedProp(password)"){
f_submit();
}
} function f_submit(){
var userId=document.forms[0].elements["reservedProp(userId)"].value;
if(userId==""){
alert("请输入帐号");
document.forms[0].elements["reservedProp(userId)"].focus();
document.forms[0].elements["reservedProp(userId)"].select();
return false;
}
var password=document.forms[0].elements["reservedProp(password)"].value;
if(password==""){
alert("请输入密码");
document.forms[0].elements["reservedProp(password)"].focus();
document.forms[0].elements["reservedProp(password)"].select();
return false;
}
SetCookieTime("userId",userId,10*365);
SetCookieTime("password",password,10*365);
document.forms[0].submit();
}
</script>
<TITLE>**管理系统
</TITLE></HEAD><BODY bgColor=#3B67B1 leftMargin=0 topMargin=0>
<form name="clientDataSetForm" method="post" action="/rlzy/loginBase.do">
<table border="0" width="100%" height="100%" background="images/back.jpg" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td>
<table border="0" background="images/bg.jpg" width="800" height="560" align="center" cellpadding="0" cellspacing="0">
<tr><td height="363"> </td></tr>
<tr><td><table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr><td width="610"> </td>
<td><table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr height="10" ><td>
<input type="text" name="reservedProp(userId)" value="" onkeydown="checkKeydown(this,event)" style="cursor:text;height:20;width:120" class="free_input">
</td></tr>
<tr height="15" ><td></td></tr>
<tr height="10" ><td >
<input type="password" name="reservedProp(password)" value="" onkeydown="checkKeydown(this,event)" style="cursor: text;height=20;width=120" class="free_input">
</td></tr>
<tr height="26"><td >
<table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr><td width="33"> </td><td width="45" style="cursor:hand" onClick="f_submit()" alt="登陆按钮"> </td><td> </td>
</tr>
</table>
</td></tr>
</table>
</td></tr>
<tr><td height="103" colspan="2" >
<table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr><td width="500"> </td><td valign="top">
</td></tr>
</table>
</td></tr>
</table>
</td></tr>
</table>
</td></tr>
</table></html>
Option ExplicitPrivate Sub Form_Load()
WebBrowser1.Navigate "http://127.0.0.1/rlzy/loginPwd.jsp"
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim vDoc, vTag
Dim i As Long
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.Length - 1
If UCase(vDoc.All(i).tagName) = "INPUT" Then
Set vTag = vDoc.All(i)
If vTag.Type = "text" Then
Select Case vTag.Name
Case "reservedProp(userId)"
vTag.Value = "123" '填写用户名
End Select
End If
If vTag.Type = "password" Then
Select Case vTag.Name
Case "reservedProp(password)"
vTag.Value = "2" '填写密码
End Select
End If
If vTag.Type = "submit" And vTag.Value = "登录" Then '登陆按钮
vTag.Click
End If
End If
Debug.Print UCase(vDoc.All(i).tagName)
Next i
End Sub问题:用户名和密码能自动填充,但因登陆按钮不是个input对象,如何提交?
If UCase(vDoc.All(I).tagName) = "BUTTON" Then
Set nTag = vDoc.All(I)
If nTag.Type = "submit" Then
nTag.Click
End If
<tr> <td width="33"> </td> <td width="45" style="cursor:hand" onClick="f_submit()" alt="登陆按钮"> </td> <td> </td></tr>
找出登陆按钮的链接的URLIf vTag.name ="登录" and vtag.href="网页的URL" Then
vTag.Click
在最后直接调用form对象的submit方法即可vDoc.getElementsByName("clientDataSetForm")(0).submit
自己解决了,5楼的答案最接近,谢谢各位的帮助