如何在WebBrowser中实现select的onchange事件,在线等,急!!!!!(150分)

  • 主题发起人 主题发起人 leafv
  • 开始时间 开始时间
L

leafv

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟要实现一个自动登陆功能,登陆页面代码如下:
function checkloginuser() {
if( document.loginform.phonenumber2.value=="") {
alert("请输入用户号码!");
document.loginform.phonenumber2.focus();
} else if(!isNumbers(document.loginform.phonenumber2.value)) {
alert("用户号码必须是数字!");
document.loginform.phonenumber2.focus();
} else if(1 == "0" && document.loginform.validate.value == ""){
alert("请输入验证码!");
document.loginform.validate.focus();
}else if(0 == "0" && document.loginform.localcode.value == ""){
alert("请选择区号!");
document.loginform.localcodeselect.focus();
}else {
loginform.phonenumber.value = loginform.localcode.value + loginform.phonenumber2.value ;
loginform.action='http://www.******.com:80/user/querypwd.do';
loginform.submit();
}
}
function localCodeChg(obj)
{
var selectVal = obj.options[obj.selectedIndex].value;
document.loginform.localcode.value = selectVal;

}
<td valign=&quot;top&quot; bgcolor=&quot;#FFFFFF&quot;>
<table width=&quot;90%&quot; border=&quot;0&quot; align=&quot;right&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; class=&quot;zi04&quot;>
<input type=&quot;hidden&quot; name=&quot;operatoraccount&quot; value=&quot;admin&quot;>
<input type=&quot;hidden&quot; name=&quot;operatorpwd&quot; value=&quot;portal&quot;>
<input type=&quot;hidden&quot; name=&quot;operator&quot; value=&quot;0&quot;>
<tr class=&quot;heihong&quot; title=&quot;用户名不要输入区号 例如:26662555(正确),075526662555(错误) ,但要选择区号!&quot;>
<td width=&quot;32%&quot; class=&quot;zi04&quot;>用户名:</td>
<td width=&quot;64%&quot;><input name=&quot;phonenumber2&quot; type=&quot;text&quot; class=&quot;zi04&quot; id=&quot;phonenumber2&quot; size=&quot;14&quot; maxlength=&quot;20&quot;>
<input name=&quot;phonenumber&quot; type=&quot;hidden&quot; >
</td>
<td width=&quot;4%&quot; rowspan=&quot;3&quot; valign=&quot;top&quot;><img src=&quot;images/spacer.gif&quot; width=&quot;1&quot; height=&quot;1&quot;></td>
</tr>
<tr>
<td class=&quot;zi04&quot;>密 码:</td>
<td><input name=&quot;password&quot; type=&quot;password&quot; class=&quot;zi04&quot; id=&quot;password&quot; size=&quot;14&quot; maxlength=&quot;10&quot;></td>
</tr>

<input type=&quot;hidden&quot; name=&quot;localcode&quot; value=&quot;&quot;>

<tr>
<td class=&quot;zi04&quot;>地区:</td>
<td>
<select name=&quot;localcodeselect&quot; onChange=&quot;localCodeChg(localcodeselect)&quot;>
<option value=&quot;&quot;>-请选地区-</option>

<option value=&quot;010&quot;>北京</option>

<option value=&quot;021&quot;>上海</option>

</select>
</td>
</tr>

我的代码是这样写的:

var
o: Olevariant;
spDisp: IDispatch;
i,j: integer;
IDoc1,Document: IHTMLDocument2;
iELC : IHTMLElementCollection ;
HtmlInputEle1:IHTMLselectelement;

str: string;
begin

if WebBrowser1<>nil then
begin
WebBrowser1.Document.QueryInterface(IHTMLDocument2,iDoc1);
if IDoc1<>nil then
begin
iELC := IDoc1.Get_all;
for j:=0 to iELC.length-1 do
begin
Application.ProcessMessages;
spDisp := ielc.item(J, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLselectelement,HtmlInputEle1))then
begin
if HtmlInputEle1.name ='localcodeselect' then
begin
HtmlInputEle1.selectedIndex :=1;

break;
end;
end;
end;
IDoc1._Release;
end;

o := WebBrowser1.OleObject.document.all.item('phonenumber2',0); //找到登录用户名的输入框
o.value := 'abc';
o := WebBrowser1.oleobject.document.all.item('password',0); //找到登录密码的输入框
o.value := '123' ;

for i := 0 to WebBrowser1.OleObject.Document.Images.Length - 1 do
begin
Document := WebBrowser1.Document as IHtmlDocument2;

Str := (Document.Images.Item(i, 0) as IHTMLImgElement).Href;

if Pos('images/0_62.gif', str) <> 0 then
begin
((Document.Images.Item(i, 0) as IHTMLImgElement) as IHTMLElement).Click;
end;
end;
end;
end;

为什么 页面会提示“请选择地区“ 我已经在 HtmlInputEle1.selectedIndex :=1; 作了选择了,怎么还是没触发页面上的 onchange 事件,请各位大大教我怎么解决 ,谢谢
 
没有人可以帮我吗?
各位大大 麻烦都看看吧 帮小弟我指条道路吧
 
后退
顶部