TWebBrowser 如何在 IE8 上将插入符位置设置为 INPUT(text) 字段的末尾
我有一个通过 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 接口但仅在 IE9 下可用
I have an application that loads a webpage via TWebBrowser and on this page I have some HTML inputs. What I want is to change the value of an input and set the caret position to the end.
This is what I have at the moment:
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;
This piece of code sets the input value and highlights the text portion.
I am aware of the IHTMLInputTextElement2 Interface but it is only available from IE9
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用
IHTMLTxtRange
You should use
IHTMLTxtRange