小弟要实现一个自动登陆功能,登陆页面代码如下:
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="top" bgcolor="#FFFFFF">
 <table width="90%" border="0" align="right" cellpadding="2" cellspacing="0" class="zi04">
  <input type="hidden" name="operatoraccount" value="admin">
          <input type="hidden" name="operatorpwd" value="portal">
          <input type="hidden" name="operator" value="0">
          <tr class="heihong"  title="用户名不要输入区号 例如:26662555(正确),075526662555(错误) ,但要选择区号!"> 
            <td width="32%" class="zi04">用户名:</td>
            <td width="64%"><input name="phonenumber2" type="text" class="zi04" id="phonenumber2" size="14" maxlength="20">
                            <input name="phonenumber" type="hidden" > 
            </td>
            <td width="4%" rowspan="3" valign="top"><img src="images/spacer.gif" width="1" height="1"></td>
          </tr>
          <tr> 
            <td class="zi04">密 码:</td>
            <td><input name="password" type="password" class="zi04" id="password" size="14" maxlength="10"></td>
          </tr>
     
   <input type="hidden" name="localcode" value="">
       
           <tr>
             <td class="zi04">地区:</td>
               <td>
                 <select name="localcodeselect"  onChange="localCodeChg(localcodeselect)">
          <option value="">-请选地区-</option>
    
                  <option value="010">北京</option>
              
                  <option value="021">上海</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 事件,请各位大大教我怎么解决 ,谢谢

解决方案 »

  1.   

    或者你直接用idhttp,模拟IE发包
      

  2.   

    兄弟不行噢 我必须要用WebBrowser1控件哦
      

  3.   

    我怎么没看到 HtmlInputEle1.selectedIndex :=1了?
    另外,你就算这样就能触发onchange了吗,不如直接调用
    <select name="localcodeselect"  onChange="localCodeChg(localcodeselect)">
    里面的localCodeChg(1)试试
      

  4.   

    TO dibaicai
    我的代码里面有
    if SUCCEEDED(spDisp.QueryInterface(IHTMLselectelement,HtmlInputEle1))then
    begin
    if HtmlInputEle1.name ='localcodeselect' then
    begin
    HtmlInputEle1.selectedIndex :=1;break;
    end;
    end;
    这种不能触发onchange 我试过了
    请脚下怎么调用localcodechg(1)
    如果可以 请把代码写出来 谢谢
      

  5.   

    具体我也没试过,不知道response能否实现,我原来用的是idhttp
    你可以到网上查查
      

  6.   

    to dabaicai
    能把你的代码发给我看看吗
      

  7.   

    我有解决方案 给我邮件 我发代码给你 [email protected]