加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – TWebBrowser如何在IE8上将插入位置设置为INPUT(文本)

发布时间:2020-12-15 09:24:48 所属栏目:大数据 来源:网络整理
导读:我有一个通过TWebBrowser加载网页的应用程序,在这个页面上我有一些 HTML输入.我想要的是更改输入的值并将插入位置设置为结尾. 这就是我现在所拥有的: procedure SetInputValue(Document : IHTMLDocument2; const ElementId,NewValue : String);var Doc : IH
我有一个通过TWebBrowser加载网页的应用程序,在这个页面上我有一些 HTML输入.我想要的是更改输入的值并将插入位置设置为结尾.

这就是我现在所拥有的:

procedure SetInputValue(Document : IHTMLDocument2; const ElementId,NewValue : String);

var Doc   : IHTMLDocument3;
    El    : IHTMLElement;

begin
 Doc := Document as IHTMLDocument3;
 if Assigned(Doc) then
  begin
   El := Doc.getElementById(ElementId);
   if Assigned(El) then
    begin
     if El.tagName = 'INPUT' then
      (El as IHTMLInputElement).Value := NewValue;
      (El as IHTMLInputElement).select;
    end;
  end;
end;

这段代码设置输入值并突出显示文本部分.
我知道IHTMLInputTextElement2 Interface但它只能从IE9获得

解决方法

你应该使用IHTMLTxtRange

var Tr: IHTMLTxtRange;

Tr := (El as IHTMLInputElement).createTextRange;
Tr.collapse(true);
Tr.moveEnd('character',Length(NewValue));
Tr.moveStart('character',Length(NewValue));
Tr.select();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读