在 TWebBrowser 控件中执行javascript代码

页面上包含 Jquery ,所以在delphi中定义的js代码是 jquery代码

 

procedure TFormLogin.Login();
var
  JSFun, newPw: 
string;
begin
  newPw :
= '<input name=''pw'' id=''pw'' type=''text'' class=''input'' tabindex=''2'' maxlength=''16'' onkeypress=''if(event.keyCode == 13){login();}'' autocomplete=''off'' value=''' + edtPwd.Text + '''>';
  
try
    
// JSFun := 'login_tab_click(''nexon'');'// 转到左侧
    JSFun :
= 'login_tab_click(''dnf'');'// 转到右侧
    htmlWindow.execScript(JSFun, 
'JavaScript');
    JSFun :
= '$("#id").focus();$("#id").val("' + edtUName.Text + '");';
    htmlWindow.execScript(JSFun, 
'JavaScript');
    JSFun :
= '$("#pw").click();$("#pw").replaceWith("' + newPw + '");';
    htmlWindow.execScript(JSFun, 
'JavaScript');
    JSFun :
= 'login();';
    htmlWindow.execScript(JSFun, 
'JavaScript');
  
except
  
end;
end;

 

posted @ 2010-10-16 13:35  芬奇  阅读(527)  评论(0编辑  收藏  举报